Top |
Functions
Properties
GType * | add-websocket-extension | Write |
gpointer | async-context | Read / Write / Construct Only |
GStrv | http-aliases | Read / Write |
GStrv | https-aliases | Read / Write |
SoupAddress * | interface | Read / Write / Construct Only |
guint | port | Read / Write / Construct Only |
gboolean | raw-paths | Read / Write / Construct Only |
GType * | remove-websocket-extension | Write |
gchar * | server-header | Read / Write / Construct |
gchar * | ssl-cert-file | Read / Write / Construct Only |
gchar * | ssl-key-file | Read / Write / Construct Only |
GTlsCertificate * | tls-certificate | Read / Write / Construct Only |
Signals
void | request-aborted | Run First |
void | request-finished | Run First |
void | request-read | Run First |
void | request-started | Run First |
Types and Values
SoupServer | |
enum | SoupServerListenOptions |
#define | SOUP_SERVER_ADD_WEBSOCKET_EXTENSION |
#define | SOUP_SERVER_REMOVE_WEBSOCKET_EXTENSION |
typedef | SoupClientContext |
#define | SOUP_SERVER_TLS_CERTIFICATE |
#define | SOUP_SERVER_RAW_PATHS |
#define | SOUP_SERVER_SERVER_HEADER |
#define | SOUP_SERVER_HTTP_ALIASES |
#define | SOUP_SERVER_HTTPS_ALIASES |
Description
SoupServer implements a simple HTTP server.
(The following documentation describes the current SoupServer API, available in libsoup 2.48 and later. See the section "The Old SoupServer Listening API" in the server how-to documentation for details on the older SoupServer API.)
To begin, create a server using soup_server_new()
. Add at least one
handler by calling soup_server_add_handler()
or
soup_server_add_early_handler()
; 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 “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 SoupMessage signals.
Once the headers have been read, SoupServer will check if there is
a SoupAuthDomain (qv) covering the Request-URI; if so, and if the
message does not contain suitable authorization, then the
SoupAuthDomain will set a status of SOUP_STATUS_UNAUTHORIZED
on
the message.
After checking for authorization, SoupServer will look for "early"
handlers (added with soup_server_add_early_handler()
) 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_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_STATUS_NOT_FOUND
to
the client.
Otherwise (assuming no previous step assigned a status to the
message) any "normal" handlers (added with
soup_server_add_handler()
) 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_STATUS_SWITCHING_PROTOCOLS
or
SOUP_STATUS_BAD_REQUEST
accordingly.
If the message still has no status code at this point (and has not
been paused with soup_server_pause_message()
), then it will be
given a status of SOUP_STATUS_INTERNAL_SERVER_ERROR
(because at
least one handler ran, but returned without assigning a status).
Finally, the server will emit “request-finished” (or “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 either set the
SOUP_SERVER_TLS_CERTIFICATE
property when creating the server, or
else call soup_server_set_ssl_certificate()
after creating it.
Once the server is set up, make one or more calls to
soup_server_listen()
, soup_server_listen_local()
, or
soup_server_listen_all()
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
SoupServers, 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 GMainContext.
Functions
soup_server_new ()
SoupServer * soup_server_new (const char *optname1
,...
);
Creates a new SoupServer. This is exactly equivalent to calling
g_object_new()
and specifying SOUP_TYPE_SERVER
as the type.
Parameters
optname1 |
name of first property to set |
|
... |
value of |
Returns
a new SoupServer. If you are using
certain legacy properties, this may also return NULL
if an error
occurs.
[nullable]
soup_server_set_ssl_cert_file ()
gboolean soup_server_set_ssl_cert_file (SoupServer *server
,const char *ssl_cert_file
,const char *ssl_key_file
,GError **error
);
Sets server
up to do https, using the SSL/TLS certificate
specified by ssl_cert_file
and ssl_key_file
(which may point to
the same file).
Alternatively, you can set the “tls-certificate” property at construction time, if you already have a GTlsCertificate.
Parameters
server |
||
ssl_cert_file |
path to a file containing a PEM-encoded SSL/TLS certificate. |
|
ssl_key_file |
path to a file containing a PEM-encoded private key. |
|
error |
return location for a GError |
Since: 2.48
soup_server_listen ()
gboolean soup_server_listen (SoupServer *server
,GSocketAddress *address
,SoupServerListenOptions options
,GError **error
);
This attempts to set up server
to listen for connections on
address
.
If options
includes SOUP_SERVER_LISTEN_HTTPS
, and server
has
been configured for TLS, then server
will listen for https
connections on this port. Otherwise it will listen for plain http.
You may call this method (along with the other "listen" methods) any number of times on a server, if you want to listen on multiple ports, or set up both http and https service.
After calling this method, server
will begin accepting and
processing connections as soon as the appropriate GMainContext is
run.
Note that SoupServer never makes use of dual IPv4/IPv6 sockets; if
address
is an IPv6 address, it will only accept IPv6 connections.
You must configure IPv4 listening separately.
Parameters
server |
||
address |
the address of the interface to listen on |
|
options |
listening options for this server |
|
error |
return location for a GError |
Returns
TRUE
on success, FALSE
if address
could not be
bound or any other error occurred (in which case error
will be
set).
Since: 2.48
soup_server_listen_all ()
gboolean soup_server_listen_all (SoupServer *server
,guint port
,SoupServerListenOptions options
,GError **error
);
This attempts to set up server
to listen for connections on all
interfaces on the system. (That is, it listens on the addresses
0.0.0.0
and/or ::
, depending
on whether options
includes SOUP_SERVER_LISTEN_IPV4_ONLY
,
SOUP_SERVER_LISTEN_IPV6_ONLY
, or neither.) If port
is specified,
server
will listen on that port. If it is 0, server
will find an
unused port to listen on. (In that case, you can use
soup_server_get_uris()
to find out what port it ended up choosing.)
See soup_server_listen()
for more details.
Parameters
server |
||
port |
the port to listen on, or 0 |
|
options |
listening options for this server |
|
error |
return location for a GError |
Returns
TRUE
on success, FALSE
if port
could not be bound
or any other error occurred (in which case error
will be set).
Since: 2.48
soup_server_listen_local ()
gboolean soup_server_listen_local (SoupServer *server
,guint port
,SoupServerListenOptions options
,GError **error
);
This attempts to set up server
to listen for connections on
"localhost" (that is, 127.0.0.1
and/or
::1
, depending on whether options
includes
SOUP_SERVER_LISTEN_IPV4_ONLY
, SOUP_SERVER_LISTEN_IPV6_ONLY
, or
neither). If port
is specified, server
will listen on that port.
If it is 0, server
will find an unused port to listen on. (In that
case, you can use soup_server_get_uris()
to find out what port it
ended up choosing.)
See soup_server_listen()
for more details.
Parameters
server |
||
port |
the port to listen on, or 0 |
|
options |
listening options for this server |
|
error |
return location for a GError |
Returns
TRUE
on success, FALSE
if port
could not be bound
or any other error occurred (in which case error
will be set).
Since: 2.48
soup_server_listen_socket ()
gboolean soup_server_listen_socket (SoupServer *server
,GSocket *socket
,SoupServerListenOptions options
,GError **error
);
This attempts to set up server
to listen for connections on
socket
.
See soup_server_listen()
for more details.
Parameters
server |
||
socket |
a listening GSocket |
|
options |
listening options for this server |
|
error |
return location for a GError |
Since: 2.48
soup_server_listen_fd ()
gboolean soup_server_listen_fd (SoupServer *server
,int fd
,SoupServerListenOptions options
,GError **error
);
This attempts to set up server
to listen for connections on
fd
.
See soup_server_listen()
for more details.
Note that server
will close fd
when you free it or call
soup_server_disconnect()
.
Parameters
server |
||
fd |
the file descriptor of a listening socket |
|
options |
listening options for this server |
|
error |
return location for a GError |
Since: 2.48
soup_server_get_listeners ()
GSList *
soup_server_get_listeners (SoupServer *server
);
Gets server
's list of listening sockets.
You should treat these sockets as read-only; writing to or
modifiying any of these sockets may cause server
to malfunction.
(Beware that in contrast to the old soup_server_get_listener()
, this
function returns GSockets, not SoupSockets.)
soup_server_get_uris ()
GSList *
soup_server_get_uris (SoupServer *server
);
Gets a list of URIs corresponding to the interfaces server
is
listening on. These will contain IP addresses, not hostnames, and
will also indicate whether the given listener is http or https.
Note that if you used soup_server_listen_all()
, the returned URIs
will use the addresses 0.0.0.0
and
::
, rather than actually returning separate URIs
for each interface on the system.
Returns
a list of SoupURIs, which you must free when you are done with it.
[transfer full][element-type Soup.URI]
Since: 2.48
soup_server_disconnect ()
void
soup_server_disconnect (SoupServer *server
);
Closes and frees server
's listening sockets. If you are using the
old SoupServer APIs, this also includes the effect of
soup_server_quit()
.
Note that if there are currently requests in progress on server
,
that they will continue to be processed if server
's GMainContext
is still running.
You can call soup_server_listen()
, etc, after calling this function
if you want to start listening again.
soup_server_is_https ()
gboolean
soup_server_is_https (SoupServer *server
);
Checks whether server
is capable of https.
In order for a server to run https, you must call
soup_server_set_ssl_cert_file()
, or set the
“tls-certificate” property, to provide it with a
certificate to use.
If you are using the deprecated single-listener APIs, then a return
value of TRUE
indicates that the SoupServer serves https
exclusively. If you are using soup_server_listen()
, etc, then a
TRUE
return value merely indicates that the server is
able to do https, regardless of whether it
actually currently is or not. Use soup_server_get_uris()
to see if
it currently has any https listeners.
soup_server_accept_iostream ()
gboolean soup_server_accept_iostream (SoupServer *server
,GIOStream *stream
,GSocketAddress *local_addr
,GSocketAddress *remote_addr
,GError **error
);
Add a new client stream to the server
.
Parameters
server |
||
stream |
a GIOStream |
|
local_addr |
the local GSocketAddress associated with the |
[allow-none] |
remote_addr |
the remote GSocketAddress associated with the |
[allow-none] |
error |
return location for a GError |
Returns
TRUE
on success, FALSE
if the stream could not be
accepted or any other error occurred (in which case error
will be
set).
Since: 2.50
SoupServerCallback ()
void (*SoupServerCallback) (SoupServer *server
,SoupMessage *msg
,const char *path
,GHashTable *query
,SoupClientContext *client
,gpointer user_data
);
A callback used to handle requests to a SoupServer.
path
and query
contain the likewise-named components of the
Request-URI, subject to certain assumptions. By default,
SoupServer decodes all percent-encoding in the URI path, such that
"/foo%2Fbar" is treated the same as "/foo/bar". If your
server is serving resources in some non-POSIX-filesystem namespace,
you may want to distinguish those as two distinct paths. In that
case, you can set the SOUP_SERVER_RAW_PATHS
property when creating
the SoupServer, and it will leave those characters undecoded. (You
may want to call soup_uri_normalize()
to decode any percent-encoded
characters that you aren't handling specially.)
query
contains the query component of the Request-URI parsed
according to the rules for HTML form handling. Although this is the
only commonly-used query string format in HTTP, there is nothing
that actually requires that HTTP URIs use that format; if your
server needs to use some other format, you can just ignore query
,
and call soup_message_get_uri()
and parse the URI's query field
yourself.
See soup_server_add_handler()
and soup_server_add_early_handler()
for details of what handlers can/should do.
Parameters
server |
the SoupServer |
|
msg |
the message being processed |
|
path |
the path component of |
|
query |
the parsed query
component of |
[element-type utf8 utf8][allow-none] |
client |
additional contextual information about the client |
|
user_data |
the data passed to |
soup_server_add_handler ()
void soup_server_add_handler (SoupServer *server
,const char *path
,SoupServerCallback callback
,gpointer user_data
,GDestroyNotify destroy
);
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 “method”,
“request-headers”, and “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 “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.
soup_server_add_early_handler ()
void soup_server_add_early_handler (SoupServer *server
,const char *path
,SoupServerCallback callback
,gpointer user_data
,GDestroyNotify destroy
);
Adds an "early" handler to server
for requests under path
. Note
that "normal" and "early" handlers are matched up together, so if
you add a normal handler for "/foo" and an early handler for
"/foo/bar", then a request to "/foo/bar" (or any path below it)
will run only the early handler. (But if you add both handlers at
the same path, then both will get run.)
For requests under path
(that have not already been assigned a
status code by a SoupAuthDomain or a signal handler), callback
will be invoked after receiving the request headers, but before
receiving the request body; the message's “method” and
“request-headers” fields will be filled in.
Early handlers are generally used for processing requests with
request bodies in a streaming fashion. If you determine that the
request will contain a message body, normally you would call
soup_message_body_set_accumulate()
on the message's
“request-body” to turn off request-body accumulation,
and connect to the message's “got-chunk” signal to
process each chunk as it comes in.
To complete the message processing after the full message body has
been read, you can either also connect to “got-body”,
or else you can register a non-early handler for path
as well. As
long as you have not set the “status-code” by the time
“got-body” is emitted, the non-early handler will be
run as well.
Parameters
server |
||
path |
the toplevel path for the handler. |
[allow-none] |
callback |
callback to invoke for requests under |
|
user_data |
data for |
|
destroy |
destroy notifier to free |
Since: 2.50
soup_server_remove_handler ()
void soup_server_remove_handler (SoupServer *server
,const char *path
);
Removes all handlers (early and normal) registered at path
.
SoupServerWebsocketCallback ()
void (*SoupServerWebsocketCallback) (SoupServer *server
,SoupWebsocketConnection *connection
,const char *path
,SoupClientContext *client
,gpointer user_data
);
A callback used to handle WebSocket requests to a SoupServer. The callback will be invoked after sending the handshake response back to the client (and is only invoked if the handshake was successful).
path
contains the path of the Request-URI, subject to the same
rules as SoupServerCallback (qv).
Parameters
server |
the SoupServer |
|
path |
the path component of |
|
connection |
the newly created WebSocket connection |
|
client |
additional contextual information about the client |
|
user_data |
the data passed to |
soup_server_add_websocket_handler ()
void soup_server_add_websocket_handler (SoupServer *server
,const char *path
,const char *origin
,char **protocols
,SoupServerWebsocketCallback callback
,gpointer user_data
,GDestroyNotify destroy
);
Adds a WebSocket 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.)
When a path has a WebSocket handler registered, server
will check
incoming requests for WebSocket handshakes after all other handlers
have run (unless some earlier handler has already set a status code
on the message), and update the request's status, response headers,
and response body accordingly.
If origin
is non-NULL
, then only requests containing a matching
"Origin" header will be accepted. If protocols
is non-NULL
, then
only requests containing a compatible "Sec-WebSocket-Protocols"
header will be accepted. More complicated requirements can be
handled by adding a normal handler to path
, and having it perform
whatever checks are needed (possibly calling
soup_server_check_websocket_handshake()
one or more times), and
setting a failure status code if the handshake should be rejected.
Parameters
server |
||
path |
the toplevel path for the handler. |
[allow-none] |
origin |
the origin of the connection. |
[allow-none] |
protocols |
the protocols supported by this handler. |
[allow-none][array zero-terminated=1] |
callback |
callback to invoke for successful WebSocket requests under |
|
user_data |
data for |
|
destroy |
destroy notifier to free |
soup_server_add_websocket_extension ()
void soup_server_add_websocket_extension (SoupServer *server
,GType extension_type
);
Add support for a WebSocket extension of the given extension_type
.
When a WebSocket client requests an extension of extension_type
,
a new SoupWebsocketExtension of type extension_type
will be created
to handle the request.
You can also add support for a WebSocket extension to the server at
construct time by using the SOUP_SERVER_ADD_WEBSOCKET_EXTENSION
property.
Note that SoupWebsocketExtensionDeflate is supported by default, use
soup_server_remove_websocket_extension()
if you want to disable it.
Since: 2.68
soup_server_remove_websocket_extension ()
void soup_server_remove_websocket_extension (SoupServer *server
,GType extension_type
);
Removes support for WebSocket extension of type extension_type
(or any subclass of
extension_type
) from server
. You can also remove extensions enabled by default
from the server at construct time by using the SOUP_SERVER_REMOVE_WEBSOCKET_EXTENSION
property.
Since: 2.68
soup_client_context_get_local_address ()
GSocketAddress *
soup_client_context_get_local_address (SoupClientContext *client
);
Retrieves the GSocketAddress associated with the local end of a connection.
Returns
the GSocketAddress
associated with the local end of a connection, it may be
NULL
if you used soup_server_accept_iostream()
.
[nullable][transfer none]
Since: 2.48
soup_client_context_get_remote_address ()
GSocketAddress *
soup_client_context_get_remote_address
(SoupClientContext *client
);
Retrieves the GSocketAddress associated with the remote end of a connection.
Returns
the GSocketAddress
associated with the remote end of a connection, it may be
NULL
if you used soup_server_accept_iostream()
.
[nullable][transfer none]
Since: 2.48
soup_client_context_get_host ()
const char *
soup_client_context_get_host (SoupClientContext *client
);
Retrieves the IP address associated with the remote end of a connection.
Returns
the IP address associated with the remote
end of a connection, it may be NULL
if you used
soup_server_accept_iostream()
.
[nullable]
soup_client_context_get_auth_domain ()
SoupAuthDomain *
soup_client_context_get_auth_domain (SoupClientContext *client
);
Checks whether the request associated with client
has been
authenticated, and if so returns the SoupAuthDomain that
authenticated it.
soup_client_context_get_auth_user ()
const char *
soup_client_context_get_auth_user (SoupClientContext *client
);
Checks whether the request associated with client
has been
authenticated, and if so returns the username that the client
authenticated as.
soup_client_context_get_gsocket ()
GSocket *
soup_client_context_get_gsocket (SoupClientContext *client
);
Retrieves the GSocket that client
is associated with.
If you are using this method to observe when multiple requests are made on the same persistent HTTP connection (eg, as the ntlm-test test program does), you will need to pay attention to socket destruction as well (eg, by using weak references), so that you do not get fooled when the allocator reuses the memory address of a previously-destroyed socket to represent a new socket.
Returns
the GSocket that client
is
associated with, NULL
if you used soup_server_accept_iostream()
.
[nullable][transfer none]
Since: 2.48
soup_client_context_steal_connection ()
GIOStream *
soup_client_context_steal_connection (SoupClientContext *client
);
"Steals" the HTTP connection associated with client
from its
SoupServer. This happens immediately, regardless of the current
state of the connection; if the response to the current
SoupMessage has not yet finished being sent, then it will be
discarded; you can steal the connection from a
“wrote-informational” or “wrote-body” signal
handler if you need to wait for part or all of the response to be
sent.
Note that when calling this function from C, client
will most
likely be freed as a side effect.
Returns
the GIOStream formerly associated
with client
(or NULL
if client
was no longer associated with a
connection). No guarantees are made about what kind of GIOStream
is returned.
[transfer full]
Since: 2.50
soup_server_add_auth_domain ()
void soup_server_add_auth_domain (SoupServer *server
,SoupAuthDomain *auth_domain
);
Adds an authentication domain to server
. Each auth domain will
have the chance to require authentication for each request that
comes in; normally auth domains will require authentication for
requests on certain paths that they have been set up to watch, or
that meet other criteria set by the caller. If an auth domain
determines that a request requires authentication (and the request
doesn't contain authentication), server
will automatically reject
the request with an appropriate status (401 Unauthorized or 407
Proxy Authentication Required). If the request used the
"100-continue" Expectation, server
will reject it before the
request body is sent.
soup_server_remove_auth_domain ()
void soup_server_remove_auth_domain (SoupServer *server
,SoupAuthDomain *auth_domain
);
Removes auth_domain
from server
.
soup_server_pause_message ()
void soup_server_pause_message (SoupServer *server
,SoupMessage *msg
);
Pauses I/O on msg
. This can be used when you need to return from
the server handler without having the full response ready yet. Use
soup_server_unpause_message()
to resume I/O.
This must only be called on SoupMessages which were created by the SoupServer and are currently doing I/O, such as those passed into a SoupServerCallback or emitted in a “request-read” signal.
soup_server_unpause_message ()
void soup_server_unpause_message (SoupServer *server
,SoupMessage *msg
);
Resumes I/O on msg
. Use this to resume after calling
soup_server_pause_message()
, or after adding a new chunk to a
chunked response.
I/O won't actually resume until you return to the main loop.
This must only be called on SoupMessages which were created by the SoupServer and are currently doing I/O, such as those passed into a SoupServerCallback or emitted in a “request-read” signal.
Types and Values
enum SoupServerListenOptions
Options to pass to soup_server_listen()
, etc.
SOUP_SERVER_LISTEN_IPV4_ONLY
and SOUP_SERVER_LISTEN_IPV6_ONLY
only make sense with soup_server_listen_all()
and
soup_server_listen_local()
, not plain soup_server_listen()
(which
simply listens on whatever kind of socket you give it). And you
cannot specify both of them in a single call.
Since: 2.48
SOUP_SERVER_ADD_WEBSOCKET_EXTENSION
#define SOUP_SERVER_ADD_WEBSOCKET_EXTENSION "add-websocket-extension"
Alias for the “add-websocket-extension” property, qv.
Since: 2.68
SOUP_SERVER_REMOVE_WEBSOCKET_EXTENSION
#define SOUP_SERVER_REMOVE_WEBSOCKET_EXTENSION "remove-websocket-extension"
Alias for the “remove-websocket-extension” property, qv.
Since: 2.68
SoupClientContext
typedef struct SoupClientContext SoupClientContext;
A SoupClientContext provides additional information about the
client making a particular request. In particular, you can use
soup_client_context_get_auth_domain()
and
soup_client_context_get_auth_user()
to determine if HTTP
authentication was used successfully.
soup_client_context_get_remote_address() and/or
soup_client_context_get_host()
can be used to get information for
logging or debugging purposes. soup_client_context_get_gsocket()
may
also be of use in some situations (eg, tracking when multiple
requests are made on the same connection).
SOUP_SERVER_TLS_CERTIFICATE
#define SOUP_SERVER_TLS_CERTIFICATE "tls-certificate"
Alias for the “tls-certificate” property, qv.
Since: 2.38
SOUP_SERVER_RAW_PATHS
#define SOUP_SERVER_RAW_PATHS "raw-paths"
Alias for the “raw-paths” property. (If TRUE
,
percent-encoding in the Request-URI path will not be
automatically decoded.)
SOUP_SERVER_SERVER_HEADER
#define SOUP_SERVER_SERVER_HEADER "server-header"
Alias for the “server-header” property, qv.
SOUP_SERVER_HTTP_ALIASES
#define SOUP_SERVER_HTTP_ALIASES "http-aliases"
Alias for the “http-aliases” property, qv.
Since: 2.44
SOUP_SERVER_HTTPS_ALIASES
#define SOUP_SERVER_HTTPS_ALIASES "https-aliases"
Alias for the “https-aliases” property, qv.
Since: 2.44
Property Details
The “add-websocket-extension”
property
“add-websocket-extension” GType *
Add support for SoupWebsocketExtension of the given type.
(Shortcut for calling soup_server_add_websocket_extension()
.)
[skip]
Owner: SoupServer
Flags: Write
Allowed values: SoupWebsocketExtension
Since: 2.68
The “async-context”
property
“async-context” gpointer
The server's GMainContext, if you are using the old API.
Servers created using soup_server_listen()
will listen on
the GMainContext that was the thread-default context at
the time soup_server_listen()
was called.
SoupServer:async-context
is deprecated and should not be used in newly-written code.
The new API uses the thread-default GMainContext rather than having an explicitly-specified one.
Owner: SoupServer
Flags: Read / Write / Construct Only
The “http-aliases”
property
“http-aliases” GStrv
A NULL
-terminated array of URI schemes that should be
considered to be aliases for "http". Eg, if this included
"dav"
, than a URI of
dav://example.com/path
would be treated
identically to http://example.com/path
.
In particular, this is needed in cases where a client
sends requests with absolute URIs, where those URIs do
not use "http:".
The default value is an array containing the single element
"*"
, a special value which means that
any scheme except "https" is considered to be an alias for
"http".
See also “https-aliases”.
Owner: SoupServer
Flags: Read / Write
Since: 2.44
The “https-aliases”
property
“https-aliases” GStrv
A comma-delimited list of URI schemes that should be considered to be aliases for "https". See “http-aliases” for more information.
The default value is NULL
, meaning that no URI schemes
are considered aliases for "https".
Owner: SoupServer
Flags: Read / Write
Since: 2.44
The “interface”
property
“interface” SoupAddress *
The address of the network interface the server is
listening on, if you are using the old SoupServer API.
(This will not be set if you use soup_server_listen()
,
etc.)
SoupServer:interface
is deprecated and should not be used in newly-written code.
SoupServers can listen on multiple interfaces
at once now. Use soup_server_listen()
, etc, to listen on an
interface, and soup_server_get_uris()
to see what addresses
are being listened on.
Owner: SoupServer
Flags: Read / Write / Construct Only
The “port”
property
“port” guint
The port the server is listening on, if you are using the
old SoupServer API. (This will not be set if you use
soup_server_listen()
, etc.)
SoupServer:port
is deprecated and should not be used in newly-written code.
SoupServers can listen on multiple interfaces
at once now. Use soup_server_listen()
, etc, to listen on a
port, and soup_server_get_uris()
to see what ports are
being listened on.
Owner: SoupServer
Flags: Read / Write / Construct Only
Allowed values: <= 65536
Default value: 0
The “raw-paths”
property
“raw-paths” gboolean
If %TRUE, percent-encoding in the Request-URI path will not be automatically decoded.
Owner: SoupServer
Flags: Read / Write / Construct Only
Default value: FALSE
The “remove-websocket-extension”
property
“remove-websocket-extension” GType *
Remove support for SoupWebsocketExtension of the given type. (Shortcut for
calling soup_server_remove_websocket_extension()
.)
[skip]
Owner: SoupServer
Flags: Write
Allowed values: SoupWebsocketExtension
Since: 2.68
The “server-header”
property
“server-header” gchar *
If non-NULL
, the value to use for the "Server" header on
SoupMessages processed by this server.
The Server header is the server equivalent of the User-Agent header, and provides information about the server and its components. It contains a list of one or more product tokens, separated by whitespace, with the most significant product token coming first. The tokens must be brief, ASCII, and mostly alphanumeric (although "-", "_", and "." are also allowed), and may optionally include a "/" followed by a version string. You may also put comments, enclosed in parentheses, between or after the tokens.
Some HTTP server implementations intentionally do not use version numbers in their Server header, so that installations running older versions of the server don't end up advertising their vulnerability to specific security holes.
As with “user_agent”, if you set a
“server_header” property that has trailing whitespace,
SoupServer will append its own product token (eg,
"libsoup/2.3.2
") to the end of the
header for you.
Owner: SoupServer
Flags: Read / Write / Construct
Default value: NULL
The “ssl-cert-file”
property
“ssl-cert-file” gchar *
Path to a file containing a PEM-encoded certificate.
If you set this property and “ssl-key-file” at
construct time, then soup_server_new()
will try to read the
files; if it cannot, it will return NULL
, with no explicit
indication of what went wrong (and logging a warning with
newer versions of glib, since returning NULL
from a
constructor is illegal).
SoupServer:ssl-cert-file
is deprecated and should not be used in newly-written code.
use “tls-certificate” or
soup_server_set_ssl_certificate()
.
Owner: SoupServer
Flags: Read / Write / Construct Only
Default value: NULL
The “ssl-key-file”
property
“ssl-key-file” gchar *
Path to a file containing a PEM-encoded private key. See “ssl-cert-file” for more information about how this is used.
SoupServer:ssl-key-file
is deprecated and should not be used in newly-written code.
use “tls-certificate” or
soup_server_set_ssl_certificate()
.
Owner: SoupServer
Flags: Read / Write / Construct Only
Default value: NULL
The “tls-certificate”
property
“tls-certificate” GTlsCertificate *
A GTlsCertificate that has a “private-key” set. If this is set, then the server will be able to speak https in addition to (or instead of) plain http.
Alternatively, you can call soup_server_set_ssl_cert_file()
to have SoupServer read in a a certificate from a file.
Owner: SoupServer
Flags: Read / Write / Construct Only
Since: 2.38
Signal Details
The “request-aborted”
signal
void user_function (SoupServer *server, SoupMessage *message, SoupClientContext *client, gpointer user_data)
Emitted when processing has failed for a message; this could mean either that it could not be read (if “request_read” has not been emitted for it yet), or that the response could not be written back (if “request_read” has been emitted but “request_finished” has not been).
message
is in an undefined state when this signal is
emitted; the signal exists primarily to allow the server to
free any state that it may have allocated in
“request_started”.
Parameters
server |
the server |
|
message |
the message |
|
client |
the client context |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
The “request-finished”
signal
void user_function (SoupServer *server, SoupMessage *message, SoupClientContext *client, gpointer user_data)
Emitted when the server has finished writing a response to a request.
Parameters
server |
the server |
|
message |
the message |
|
client |
the client context |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
The “request-read”
signal
void user_function (SoupServer *server, SoupMessage *message, SoupClientContext *client, gpointer user_data)
Emitted when the server has successfully read a request.
message
will have all of its request-side information
filled in, and if the message was authenticated, client
will have information about that. This signal is emitted
before any (non-early) handlers are called for the message,
and if it sets the message's status_code, then normal
handler processing will be skipped.
Parameters
server |
the server |
|
message |
the message |
|
client |
the client context |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
The “request-started”
signal
void user_function (SoupServer *server, SoupMessage *message, SoupClientContext *client, gpointer user_data)
Emitted when the server has started reading a new request.
message
will be completely blank; not even the
Request-Line will have been read yet. About the only thing
you can usefully do with it is connect to its signals.
If the request is read successfully, this will eventually be followed by a “request_read” signal. If a response is then sent, the request processing will end with a “request_finished” signal. If a network error occurs, the processing will instead end with “request_aborted”.
Parameters
server |
the server |
|
message |
the new message |
|
client |
the client context |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First