Server.addHandler

void addHandler(string path, soup.types.ServerCallback callback)

Adds a handler to server for requests prefixed by path.

If path is null or "/", then this will be the default handler for all requests that don't have a more specific handler. (Note though that if you want to handle requests to the special "*" URI, you must explicitly register a handler for "*"; the default handler will not be used for that case.)

For requests under path (that have not already been assigned a status code by a classAuthDomain, an early server handler, or a signal handler), callback will be invoked after receiving the request body; the classServerMessage's method, request-headers, and request-body properties will be set.

After determining what to do with the request, the callback must at a minimum call [soup.server_message.ServerMessage.setStatus] on the message to set the response status code. Additionally, it may set response headers and/or fill in the response body.

If the callback cannot fully fill in the response before returning (eg, if it needs to wait for information from a database, or another network server), it should call [soup.server_message.ServerMessage.pause] to tell server to not send the response right away. When the response is ready, call [soup.server_message.ServerMessage.unpause] to cause it to be sent.

To send the response body a bit at a time using "chunked" encoding, first call [soup.message_headers.MessageHeaders.setEncoding] to set [soup.types.Encoding.Chunked] on the response-headers. Then call [soup.message_body.MessageBody.append] (or [soup.message_body.MessageBody.appendBytes])) to append each chunk as it becomes ready, and [soup.server_message.ServerMessage.unpause] to make sure it's running. (The server will automatically pause the message if it is using chunked encoding but no more chunks are available.) When you are done, call [soup.message_body.MessageBody.complete] to indicate that no more chunks are coming.

Parameters

paththe toplevel path for the handler
callbackcallback to invoke for requests under path