sigildocs

(sigil http server)

(sigil http server) - HTTP Server Implementation

Provides the HTTP server with support for:

  • Non-blocking I/O via coroutines
  • Multiple concurrent connections
  • Streaming responses

Exports

http-serverprocedure

HTTP Server Record

http-server?procedure

Test if a value is a http-server struct.

Get the handler field of a http-server struct.

Get the port field of a http-server struct.

Get the host field of a http-server struct.

Get the backlog field of a http-server struct.

Get the timeout field of a http-server struct.

Get the max-request-size field of a http-server struct.

Get the socket field of a http-server struct.

Get the running field of a http-server struct.

Get the clients field of a http-server struct.

http-clientprocedure

Client connection state

http-client?procedure

Test if a value is a http-client struct.

Get the socket field of a http-client struct.

Get the buffer field of a http-client struct.

Get the headers-complete field of a http-client struct.

Get the content-length field of a http-client struct.

Get the request field of a http-client struct.

Get the response-started field of a http-client struct.

Get the created-at field of a http-client struct.

Check if server is currently running.

Returns #t if the server has been started and not stopped.

(define srv (make-http-server handler))
(http-server-running? srv)  ; => #f

Start the server (blocking - runs event loop)

Stop the server gracefully Closes the listening socket and all active client connections

Process one round of I/O (for custom event loops)

server-loopprocedure

Main server loop

When running inside a channel-run context, cooperates with other tasks via await-readable. Otherwise uses traditional socket-select.

Process connections using socket-select

Accept a new client connection

Process clients that have readable data

Handle data from a client Returns updated client or #f to remove

Try to parse request from buffer and handle it Returns updated client, or #f to remove client

Continue reading body data

Finalize and handle the complete request

Parse just the headers, returning (method path query version . headers-dict) or #f on error

Find end of headers (rnrn)

Parse header lines into dict with lowercase keyword keys

Handle a complete request

send-responseprocedure

Send a response to socket

Send an error response