Creates an instance of a HTTP server.
The IP address or hostname the server will bind to.
The port number the server will listen on.
The request handler to be used when serving requests
Optionaloptions: HttpServerOptions
Limits, deadlines, per-pump budgets and the clock; see HttpServerOptions.
Protected ReadonlyhandlerThe request handler to be used when serving requests
ProtectedloggerProtectedserverThe underlying TCP server.
Legacy entry point, kept for compatibility: it runs one pump.
Unlike earlier versions it neither handles exactly one client nor finishes a request within the call: a call may accept several clients and advance several connections, and a request may take several calls to be read and answered. Keep calling it repeatedly, as before.
Use pump.
Closes the listening socket and every open connection and releases their buffers. Safe to call more than once; later calls, and later pumps, do nothing.
The number of open connections. (A method rather than a getter: accessors would slow every property access on the server and its subclasses in the generated Lua.)
Does a bounded amount of work and returns: accepts up to maxAcceptsPerPump new connections (while fewer
than maxConnections are open), then visits open connections round-robin within the per-pump budgets.
Call it repeatedly, for example from a timer callback; it never waits for a socket.
What this pump did. Cheap to ignore; useful for instrumentation.
An HTTP/1.1 server driven cooperatively from a host loop or timer callback.
Every socket is non-blocking. Each call to pump accepts a bounded number of new connections and then visits the open connections round-robin, starting where the previous pump stopped. A visit does whatever progress is possible without waiting: it reads available request bytes, runs the request handler once the request is complete, and writes as much of the response as the socket accepts. A connection that cannot make progress keeps its state and is revisited on a later pump, so an idle or slow client never holds up the others.
Each connection serves one request and is closed once the whole response has been handed to the socket. Every response carries
Connection: close. Keep-alive, pipelining and chunked request bodies are not supported; see the package README for the request forms that are rejected, and HttpServerOptions for the limits, deadlines and per-pump budgets.The request handler is synchronous and runs to completion inside a pump; the pump's time budget cannot interrupt it, but no new handler starts once the budget is spent.
Example