soup.server
Module for [Server] class
Types 3
A HTTP server.
#SoupServer implements a simple HTTP server.
To begin, create a server using [soup.server.Server.new_]. Add at least one handler by calling [soup.server.Server.addHandler] or [soup.server.Server.addEarlyHandler]; the handler will be called to process any requests underneath the path you pass. (If you want all requests to go to the same handler, just pass "/" (or null) for the path.)
When a new connection is accepted (or a new request is started on an existing persistent connection), the #SoupServer will emit signal@Server::request-started and then begin processing the request as described below, but note that once the message is assigned a status-code, then callbacks after that point will be skipped. Note also that it is not defined when the callbacks happen relative to various class@ServerMessage signals.
Once the headers have been read, #SoupServer will check if there is a class@AuthDomain (qv) covering the Request-URI; if so, and if the message does not contain suitable authorization, then the class@AuthDomain will set a status of [soup.types.Status.Unauthorized] on the message.
After checking for authorization, #SoupServer will look for "early" handlers (added with [soup.server.Server.addEarlyHandler]) matching the Request-URI. If one is found, it will be run; in particular, this can be used to connect to signals to do a streaming read of the request body.
(At this point, if the request headers contain Expect:
100-continue, and a status code has been set, then #SoupServer will skip the remaining steps and return the response. If the request headers contain Expect:
100-continue and no status code has been set, #SoupServer will return a [soup.types.Status.Continue] status before continuing.)
The server will then read in the response body (if present). At this point, if there are no handlers at all defined for the Request-URI, then the server will return [soup.types.Status.NotFound] to the client.
Otherwise (assuming no previous step assigned a status to the message) any "normal" handlers (added with [soup.server.Server.addHandler]) for the message's Request-URI will be run.
Then, if the path has a WebSocket handler registered (and has not yet been assigned a status), #SoupServer will attempt to validate the WebSocket handshake, filling in the response and setting a status of [soup.types.Status.SwitchingProtocols] or [soup.types.Status.BadRequest] accordingly.
If the message still has no status code at this point (and has not been paused with [soup.server_message.ServerMessage.pause]), then it will be given a status of [soup.types.Status.InternalServerError] (because at least one handler ran, but returned without assigning a status).
Finally, the server will emit signal@Server::request-finished (or signal@Server::request-aborted if an I/O error occurred before handling was completed).
If you want to handle the special "" URI (eg, "OPTIONS "), you must explicitly register a handler for "*"; the default handler will not be used for that case.
If you want to process https connections in addition to (or instead of) http connections, you can set the property@Server:tls-certificate property.
Once the server is set up, make one or more calls to [soup.server.Server.listen], [soup.server.Server.listenLocal], or [soup.server.Server.listenAll] to tell it where to listen for connections. (All ports on a #SoupServer use the same handlers; if you need to handle some ports differently, such as returning different data for http and https, you'll need to create multiple [soup.server.Server]s, or else check the passed-in URI in the handler function.).
#SoupServer will begin processing connections as soon as you return to (or start) the main loop for the current thread-default [glib.main_context.MainContext].
Server self()Returns `this`, for use in `with` statements.ServerGidBuilder builder()Get builder for [soup.server.Server] Returns: New builder objectbool rawPaths() @propertyGet `rawPaths` property. Returns: If true, percent-encoding in the Request-URI path will not be automatically decoded.void serverHeader(string propval) @propertySet `serverHeader` property. Params: propval = Server header.gio.types.TlsAuthenticationMode tlsAuthMode() @propertyGet `tlsAuthMode` property. Returns: A [gio.types.TlsAuthenticationMode] for SSL/TLS client authentication.void tlsAuthMode(gio.types.TlsAuthenticationMode propval) @propertySet `tlsAuthMode` property. Params: propval = A [gio.types.TlsAuthenticationMode] for SSL/TLS client authentication.gio.tls_certificate.TlsCertificate tlsCertificate() @propertyGet `tlsCertificate` property. Returns: A [gio.tls_certificate.TlsCertificate] that has a `property@Gio.TlsCertificate:private-key` set.void tlsCertificate(gio.tls_certificate.TlsCertificate propval) @propertySet `tlsCertificate` property. Params: propval = A [gio.tls_certificate.TlsCertificate] that has a `property@Gio.TlsCertificate:private-key` set.gio.tls_database.TlsDatabase tlsDatabase() @propertyGet `tlsDatabase` property. Returns: A [gio.tls_database.TlsDatabase] to use for validating SSL/TLS client certificates.void tlsDatabase(gio.tls_database.TlsDatabase propval) @propertySet `tlsDatabase` property. Params: propval = A [gio.tls_database.TlsDatabase] to use for validating SSL/TLS client certificates.bool acceptIostream(gio.iostream.IOStream stream, gio.socket_address.SocketAddress localAddr = null, gio.socket_address.SocketAddress remoteAddr = null)Adds a new client stream to the server.void addAuthDomain(soup.auth_domain.AuthDomain authDomain)Adds an authentication domain to server.void addEarlyHandler(string path, soup.types.ServerCallback callback)Adds an "early" handler to server for requests prefixed by path.void addHandler(string path, soup.types.ServerCallback callback)Adds a handler to server for requests prefixed by path.void addWebsocketExtension(gobject.types.GType extensionType)Add support for a WebSocket extension of the given extension_type.void addWebsocketHandler(string path, string origin, string[] protocols, soup.types.ServerWebsocketCallback callback)Adds a WebSocket handler to server for requests prefixed by path.void disconnect()Closes and frees server's listening sockets.gio.socket.Socket[] getListeners()Gets server's list of listening sockets.gio.types.TlsAuthenticationMode getTlsAuthMode()Gets the server SSL/TLS client authentication mode. Returns: a #GTlsAuthenticationModegio.tls_certificate.TlsCertificate getTlsCertificate()Gets the server SSL/TLS certificate. Returns: a #GTlsCertificate or nullgio.tls_database.TlsDatabase getTlsDatabase()Gets the server SSL/TLS database. Returns: a #GTlsDatabaseglib.uri.Uri[] getUris()Gets a list of URIs corresponding to the interfaces server is listening on.bool isHttps()Checks whether server is capable of https.bool listen(gio.socket_address.SocketAddress address, soup.types.ServerListenOptions options)Attempts to set up server to listen for connections on address.bool listenAll(uint port, soup.types.ServerListenOptions options)Attempts to set up server to listen for connections on all interfaces on the system.bool listenLocal(uint port, soup.types.ServerListenOptions options)Attempts to set up server to listen for connections on "localhost".bool listenSocket(gio.socket.Socket socket, soup.types.ServerListenOptions options)Attempts to set up server to listen for connections on socket.void pauseMessage(soup.server_message.ServerMessage msg)Pauses I/O on msg.void removeAuthDomain(soup.auth_domain.AuthDomain authDomain)Removes auth_domain from server.void removeHandler(string path)Removes all handlers (early and normal) registered at path.void removeWebsocketExtension(gobject.types.GType extensionType)Removes support for WebSocket extension of type extensiontype (or any subclass of extensiontype) from server.void setTlsAuthMode(gio.types.TlsAuthenticationMode mode)Sets server's #GTlsAuthenticationMode to use for SSL/TLS client authentication.void setTlsCertificate(gio.tls_certificate.TlsCertificate certificate)Sets server up to do https, using the given SSL/TLS certificate.void setTlsDatabase(gio.tls_database.TlsDatabase tlsDatabase)Sets server's #GTlsDatabase to use for validating SSL/TLS client certificates.void unpauseMessage(soup.server_message.ServerMessage msg)Resumes I/O on msg.gulong connectRequestAborted(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : soup.server_message.ServerMessage)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.server.Server)))
&& Parameters!T.length < 3)Connect to `RequestAborted` signal.gulong connectRequestFinished(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : soup.server_message.ServerMessage)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.server.Server)))
&& Parameters!T.length < 3)Connect to `RequestFinished` signal.gulong connectRequestRead(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : soup.server_message.ServerMessage)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.server.Server)))
&& Parameters!T.length < 3)Connect to `RequestRead` signal.gulong connectRequestStarted(T)(T callback, Flag!"After" after = No.After) if (isCallable!T
&& is(ReturnType!T == void)
&& (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : soup.server_message.ServerMessage)))
&& (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.server.Server)))
&& Parameters!T.length < 3)Connect to `RequestStarted` signal.T rawPaths(bool propval)Set `rawPaths` property. Params: propval = If true, percent-encoding in the Request-URI path will not be automatically decoded. Returns: Builder instance for fluent chainingT serverHeader(string propval)Set `serverHeader` property. Params: propval = Server header.T tlsAuthMode(gio.types.TlsAuthenticationMode propval)Set `tlsAuthMode` property. Params: propval = A [gio.types.TlsAuthenticationMode] for SSL/TLS client authentication. Returns: Builder instance for fluent chainingT tlsCertificate(gio.tls_certificate.TlsCertificate propval)Set `tlsCertificate` property. Params: propval = A [gio.tls_certificate.TlsCertificate] that has a `property@Gio.TlsCertificate:private-key` set.T tlsDatabase(gio.tls_database.TlsDatabase propval)Set `tlsDatabase` property. Params: propval = A [gio.tls_database.TlsDatabase] to use for validating SSL/TLS client certificates. Returns: Builder instance for fluent chainingFluent builder for [soup.server.Server]
Server build()