HttpServer

A simple HTTP server that accepts requests on a given port and address, and lets a configured HttpRequestHandler produce a response, to send back to the client.

Constructors

this
this(HttpRequestHandler handler, RequestWorkerPool requestWorkerPool, ServerConfig config)

Constructs a new server using the supplied handler to handle all incoming requests, as well as a supplied request worker pool.

this
this(HttpRequestHandler handler, ServerConfig config)

Constructs a new server using the supplied handler to handle all incoming requests.

this
this(HttpRequestHandlerFunction handlerFunc, ServerConfig config)

Constructs a new server using the supplied handler function to handle all incoming requests.

Members

Functions

getExceptionHandler
ServerExceptionHandler getExceptionHandler()

Gets the configured exception handler for any exceptions that occur during request handling.

getHandler
HttpRequestHandler getHandler()

Gets the configured handler for requests.

getWebSocketManager
WebSocketManager getWebSocketManager()

Gets the server's websocket manager, used to register new websocket connections, or to broadcast a message to all connected websockets.

isReady
bool isReady()

Tells whether the server is ready to receive requests. This loads the ready status safely for access by multiple threads.

reviveWebSocketManager
void reviveWebSocketManager()

Attempts to revive a dead websocket manager thread by simply replacing it with a new one and starting that. This is only meant as a means to minimize damage when there's a severe bug in websocket logic.

setExceptionHandler
void setExceptionHandler(ServerExceptionHandler exceptionHandler)

Sets the server's exception handler.

start
void start()

Starts the server on the calling thread, so that it will begin accepting HTTP requests. Once the server is able to accept requests, isReady() will return true, and will remain true until the server is stopped by calling stop(). This can be thought of as the "main loop" of the server.

startInNewThread
Thread startInNewThread()

Starts the server running in a new thread.

stop
void stop()

Shuts down the server by closing the server socket, if possible. This will block until all pending requests have been fulfilled.

Variables

config
ServerConfig config;

The server's configuration values.