Top | ![]() |
![]() |
![]() |
![]() |
gboolean | accept-certificate | Run Last |
void | disconnected | Run Last |
void | finished | Run Last |
void | got-body | Run Last |
void | got-chunk | Run First |
void | got-headers | Run Last |
void | wrote-body | Run Last |
void | wrote-body-data | Run Last |
void | wrote-chunk | Run Last |
void | wrote-headers | Run Last |
void | wrote-informational | Run Last |
A SoupServerMessage represents an HTTP message that is being sent or received on a SoupServer
SoupServer will create SoupServerMessages automatically for incoming requests, which your application will receive via handlers.
Note that libsoup's terminology here does not quite match the HTTP specification: in RFC 2616, an "HTTP-message" is either a Request, or a Response. In libsoup, a SoupServerMessage combines both the request and the response.
SoupMessageHeaders *
soup_server_message_get_request_headers
(SoupServerMessage *msg
);
Get the request headers of msg
.
SoupMessageHeaders *
soup_server_message_get_response_headers
(SoupServerMessage *msg
);
Get the response headers of msg
.
SoupMessageBody *
soup_server_message_get_request_body (SoupServerMessage *msg
);
Get the request body of msg
.
SoupMessageBody *
soup_server_message_get_response_body (SoupServerMessage *msg
);
Get the response body of msg
.
const char *
soup_server_message_get_method (SoupServerMessage *msg
);
Get the HTTP method of msg
.
SoupHTTPVersion
soup_server_message_get_http_version (SoupServerMessage *msg
);
Get the HTTP version of msg
.
void soup_server_message_set_http_version (SoupServerMessage *msg
,SoupHTTPVersion version
);
Set the HTTP version of msg
.
guint
soup_server_message_get_status (SoupServerMessage *msg
);
Get the HTTP status code of msg
.
void soup_server_message_set_status (SoupServerMessage *msg
,guint status_code
,const char *reason_phrase
);
Sets msg
's status code to status_code
. If status_code
is a
known value and reason_phrase
is NULL
, the reason_phrase will
be set automatically.
const char *
soup_server_message_get_reason_phrase (SoupServerMessage *msg
);
Get the HTTP reason phrase of msg
or NULL
.
GUri *
soup_server_message_get_uri (SoupServerMessage *msg
);
Get msg
's URI.
void soup_server_message_set_response (SoupServerMessage *msg
,const char *content_type
,SoupMemoryUse resp_use
,const char *resp_body
,gsize resp_length
);
Convenience function to set the response body of a SoupServerMessage. If
content_type
is NULL
, the response body must be empty as well.
msg |
the message |
|
content_type |
MIME Content-Type of the body. |
[nullable] |
resp_use |
a SoupMemoryUse describing how to handle |
|
resp_body |
a data buffer containing the body of the message response. |
[nullable][array length=resp_length][element-type guint8] |
resp_length |
the byte length of |
void soup_server_message_set_redirect (SoupServerMessage *msg
,guint status_code
,const char *redirect_uri
);
Sets msg
's status_code to status_code
and adds a Location header
pointing to redirect_uri
. Use this from a SoupServer when you
want to redirect the client to another URI.
redirect_uri
can be a relative URI, in which case it is
interpreted relative to msg
's current URI. In particular, if
redirect_uri
is just a path, it will replace the path
and query of msg
's URI.
GSocket *
soup_server_message_get_socket (SoupServerMessage *msg
);
Retrieves the GSocket that msg
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.
the GSocket that msg
is
associated with, NULL
if you used soup_server_accept_iostream()
.
[nullable][transfer none]
GSocketAddress *
soup_server_message_get_local_address (SoupServerMessage *msg
);
Retrieves the GSocketAddress associated with the local end of a connection.
the GSocketAddress
associated with the local end of a connection, it may be
NULL
if you used soup_server_accept_iostream()
.
[nullable][transfer none]
GSocketAddress *
soup_server_message_get_remote_address
(SoupServerMessage *msg
);
Retrieves the GSocketAddress associated with the remote end of a connection.
the GSocketAddress
associated with the remote end of a connection, it may be
NULL
if you used soup_server_accept_iostream()
.
[nullable][transfer none]
const char *
soup_server_message_get_remote_host (SoupServerMessage *msg
);
Retrieves the IP address associated with the remote end of a connection.
the IP address associated with the remote
end of a connection, it may be NULL
if you used
soup_server_accept_iostream()
.
[nullable]
gboolean
soup_server_message_is_options_ping (SoupServerMessage *msg
);
Gets if msg
represents an OPTIONS message with the path *
.
GIOStream *
soup_server_message_steal_connection (SoupServerMessage *msg
);
"Steals" the HTTP connection associated with msg
from its
SoupServer. This happens immediately, regardless of the current
state of the connection; if the response to msg
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, msg
will most
likely be freed as a side effect.
“accept-certificate”
signalgboolean user_function (SoupServerMessage *msg, GTlsCertificate *tls_peer_certificate, GTlsCertificateFlags tls_peer_errors, gpointer user_data)
Emitted during the msg
's connection TLS handshake
after client TLS certificate has been received.
You can return TRUE
to accept tls_certificate
despite
tls_errors
.
msg |
the message |
|
tls_peer_certificate |
the peer's GTlsCertificate |
|
tls_peer_errors |
the tls errors of |
|
user_data |
user data set when the signal handler was connected. |
TRUE
to accept the TLS certificate and stop other
handlers from being invoked, or FALSE
to propagate the
event further.
Flags: Run Last
“disconnected”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted when the msg
's socket is disconnected.
Flags: Run Last
“finished”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted when all HTTP processing is finished for a message. (After “wrote-body”).
Flags: Run Last
“got-body”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted after receiving the complete request body.
Flags: Run Last
“got-chunk”
signalvoid user_function (SoupServerMessage *msg, GBytes *chunk, gpointer user_data)
Emitted after receiving a chunk of a message body. Note that "chunk" in this context means any subpiece of the body, not necessarily the specific HTTP 1.1 chunks sent by the other side.
msg |
the message |
|
chunk |
the just-read chunk |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First
“got-headers”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted after receiving the Request-Line and request headers.
Flags: Run Last
“wrote-body”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted immediately after writing the complete response body for a message.
Flags: Run Last
“wrote-body-data”
signalvoid user_function (SoupServerMessage *msg, guint chunk_size, gpointer user_data)
Emitted immediately after writing a portion of the message body to the network.
msg |
the message |
|
chunk_size |
the number of bytes written |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last
“wrote-chunk”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted immediately after writing a body chunk for a message.
Note that this signal is not parallel to
“got-chunk”; it is emitted only when a complete
chunk (added with soup_message_body_append()
or
soup_message_body_append_bytes()
) has been written. To get
more useful continuous progress information, use
“wrote-body-data”.
Flags: Run Last
“wrote-headers”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted immediately after writing the response headers for a message.
Flags: Run Last
“wrote-informational”
signalvoid user_function (SoupServerMessage *msg, gpointer user_data)
Emitted immediately after writing a 1xx (Informational) response.
Flags: Run Last