Hi,
I'm working on an embedded systems project using Chibi Scheme. To start with I'm trying to get an http client and server working.
The http server seems to work ok. However, the http client hangs after connecting to it (or other websites)– reading from the socket input file object blocks without returning data.
I've tested the server using Firefox and curl, and it works fine:
$ curl -D - "
http://localhost:8000"
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
<html><body><p>3</p></body></html>
The http server logs show a successful request:
2023-03-12 20:51:18 D net-server: accepting request: 2 ::ffff:127.0.0.1
2023-03-12 20:51:18 I (request: GET "/" "HTTP/1.1" ((host . "localhost:8000") (user-agent . "curl/7.79.1") (accept . "*/*")))
2023-03-12 20:51:18 D net-server: finished: 2
But when I use the new simple client, it just hangs with no output:
$ ./examples/simple-http-client.scm
Retrieving http://localhost:8000...
However, the server shows that the client connected:
2023-03-12 20:52:06 D net-server: accepting request: 4 ::ffff:127.0.0.1
2023-03-12 20:52:06 I (request: GET "/" "HTTP/1.0" ((host . "localhost") (user-agent . "chibi") (connection . "close")))
2023-03-12 20:52:06 D net-server: finished: 4
I must be doing something wrong– does anyone see anything incorrect or missing in the http client (code below)?
-adam
Seattle, WA, USA
. . . . . . . . .
#! /usr/bin/env chibi-scheme
; Simple HTTP server
; Returns a minimal HTML page with a single number incremented
; every request. Binds to localhost port 8000.
(import (chibi) (chibi net http-server) (chibi net servlet) (chibi sxml))
(let ((count 0))
(run-http-server
8000
(lambda (cfg request next restart)
(set! count (+ 1 count))
(servlet-write request (sxml->xml `(html (body (p ,count))))))))
. . . . . . . . .
#! /usr/bin/env chibi-scheme
; Simple HTTP client
; Retrieves the contents of
http://localhost:8000(import (chibi) (chibi net) (chibi net http))
(let ((url "
http://localhost:8000"))
(display (string-append "Retrieving " url "..."))
(newline)
(display (http-get url))
(newline)
)