Server.addHandler

Adds a handler to @server for requests under @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 #SoupAuthDomain, an early #SoupServerHandler, or a signal handler), @callback will be invoked after receiving the request body; the message's #SoupMessage:method, #SoupMessage:request-headers, and #SoupMessage:request-body fields will be filled in.

After determining what to do with the request, the callback must at a minimum call soup_message_set_status() (or soup_message_set_status_full()) 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_pause_message() to tell @server to not send the response right away. When the response is ready, call soup_server_unpause_message() to cause it to be sent.

To send the response body a bit at a time using "chunked" encoding, first call soup_message_headers_set_encoding() to set %SOUP_ENCODING_CHUNKED on the #SoupMessage:response-headers. Then call soup_message_body_append() (or soup_message_body_append_buffer()) to append each chunk as it becomes ready, and soup_server_unpause_message() 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_complete() to indicate that no more chunks are coming.

class Server
void
addHandler
(
string path
,,
void* userData
,
GDestroyNotify destroy
)

Parameters

path string

the toplevel path for the handler

callback SoupServerCallback

callback to invoke for requests under @path

userData void*

data for @callback

destroy GDestroyNotify

destroy notifier to free @user_data

Meta