(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-serverprocedureHTTP Server Record
http-server?procedureTest if a value is a http-server struct.
http-server-handlerprocedureGet the handler field of a http-server struct.
http-server-portprocedureGet the port field of a http-server struct.
http-server-hostprocedureGet the host field of a http-server struct.
http-server-backlogprocedureGet the backlog field of a http-server struct.
http-server-timeoutprocedureGet the timeout field of a http-server struct.
http-server-max-request-sizeprocedureGet the max-request-size field of a http-server struct.
http-server-socketprocedureGet the socket field of a http-server struct.
http-server-runningprocedureGet the running field of a http-server struct.
http-server-clientsprocedureGet the clients field of a http-server struct.
http-clientprocedureClient connection state
http-client?procedureTest if a value is a http-client struct.
http-client-socketprocedureGet the socket field of a http-client struct.
http-client-bufferprocedureGet the buffer field of a http-client struct.
http-client-headers-completeprocedureGet the headers-complete field of a http-client struct.
http-client-content-lengthprocedureGet the content-length field of a http-client struct.
http-client-requestprocedureGet the request field of a http-client struct.
http-client-response-startedprocedureGet the response-started field of a http-client struct.
http-client-created-atprocedureGet the created-at field of a http-client struct.
http-server-running?procedureCheck 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) ; => #fhttp-server-startprocedureStart the server (blocking - runs event loop)
http-server-stopprocedureStop the server gracefully Closes the listening socket and all active client connections
http-server-tickprocedureProcess one round of I/O (for custom event loops)
server-loopprocedureMain server loop
When running inside a channel-run context, cooperates with other tasks via await-readable. Otherwise uses traditional socket-select.
process-connectionsprocedureProcess connections using socket-select
accept-new-clientprocedureAccept a new client connection
process-readable-clientsprocedureProcess clients that have readable data
handle-client-dataprocedureHandle data from a client Returns updated client or #f to remove
try-parse-and-handleprocedureTry to parse request from buffer and handle it Returns updated client, or #f to remove client
continue-body-readprocedureContinue reading body data
finalize-requestprocedureFinalize and handle the complete request
parse-headers-onlyprocedureParse just the headers, returning (method path query version . headers-dict) or #f on error
find-header-endprocedureFind end of headers (rnrn)
parse-header-linesprocedureParse header lines into dict with lowercase keyword keys
handle-requestprocedureHandle a complete request
send-responseprocedureSend a response to socket
send-error-responseprocedureSend an error response