class Server
pub class Server
An HTTP/1.1 server over a TcpListener: serve runs until shutdown.
Methods
pub static fn bind(
addr: SocketAddr,
options: ServerOptions = ServerOptions { }
): Server throws IoError
Returns a server bound to the address — port 0 for any; localAddr() says which.
Errors
Throws IoError where the address cannot be bound.
pub fn localAddr(): SocketAddr throws IoError
pub mut fn serve(handler: fn(Request) -> Response throws Error): void throws Cancelled
Accepts and serves connections, each on a task of its own, until shutdown() closes the
listener. The handler's response is written as it is; a handler that throws answers 500
with the error's message. A request the server cannot read is answered 400 and the
connection closed.
Errors
Throws Cancelled where the task is cancelled while waiting for a connection.
pub mut fn shutdown(): void
Stops the server: closes the listener — serve returns — and the connections waiting for
a request; a request under way is answered first, then its connection closes.