![]() |
![]() |
![]() |
libsoup Reference Manual | ![]() |
---|---|---|---|---|
struct SoupMessage; enum SoupMessageStatus; #define SOUP_MESSAGE_IS_STARTING (msg) enum SoupTransferEncoding; enum SoupOwnership; SoupDataBuffer; void (*SoupMessageCallbackFn) (SoupMessage *req, gpointer user_data); SoupMessage* soup_message_new (const char *method, const char *uri_string); SoupMessage* soup_message_new_from_uri (const char *method, const SoupUri *uri); void soup_message_set_request (SoupMessage *msg, const char *content_type, SoupOwnership req_owner, char *req_body, gulong req_length); void soup_message_set_response (SoupMessage *msg, const char *content_type, SoupOwnership resp_owner, char *resp_body, gulong resp_length); void soup_message_add_header (GHashTable *hash, const char *name, const char *value); const char* soup_message_get_header (GHashTable *hash, const char *name); const GSList* soup_message_get_header_list (GHashTable *hash, const char *name); void soup_message_foreach_header (GHashTable *hash, GHFunc func, gpointer user_data); void soup_message_remove_header (GHashTable *hash, const char *name); void soup_message_clear_headers (GHashTable *hash); enum SoupHttpVersion; void soup_message_set_http_version (SoupMessage *msg, SoupHttpVersion version); SoupHttpVersion soup_message_get_http_version (SoupMessage *msg); const SoupUri* soup_message_get_uri (SoupMessage *msg); void soup_message_set_uri (SoupMessage *msg, const SoupUri *uri); enum SoupMessageFlags; void soup_message_set_flags (SoupMessage *msg, guint flags); guint soup_message_get_flags (SoupMessage *msg); void soup_message_set_status (SoupMessage *msg, guint status_code); void soup_message_set_status_full (SoupMessage *msg, guint status_code, const char *reason_phrase); void soup_message_add_chunk (SoupMessage *msg, SoupOwnership owner, const char *body, guint length); void soup_message_add_final_chunk (SoupMessage *msg); SoupDataBuffer* soup_message_pop_chunk (SoupMessage *msg); gboolean soup_message_is_keepalive (SoupMessage *msg); SoupTransferEncoding soup_message_get_request_encoding (SoupMessage *msg, guint *content_length); SoupTransferEncoding soup_message_get_response_encoding (SoupMessage *msg, guint *content_length); enum SoupHandlerPhase; void soup_message_add_handler (SoupMessage *msg, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data); void soup_message_add_header_handler (SoupMessage *msg, const char *header, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data); void soup_message_add_status_code_handler (SoupMessage *msg, guint status_code, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data); void soup_message_add_status_class_handler (SoupMessage *msg, SoupStatusClass status_class, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data); void soup_message_remove_handler (SoupMessage *msg, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data); void soup_message_send_request (SoupMessage *req, SoupSocket *sock, gboolean is_via_proxy); void soup_message_read_request (SoupMessage *req, SoupSocket *sock); void soup_message_io_pause (SoupMessage *msg); void soup_message_io_unpause (SoupMessage *msg); void soup_message_io_stop (SoupMessage *msg);
GObject +----SoupMessage +----SoupServerMessage +----SoupSoapMessage +----SoupXmlrpcMessage
"finished" : Run First "got-body" : Run First "got-chunk" : Run First "got-headers" : Run First "got-informational" : Run First "restarted" : Run First "wrote-body" : Run First "wrote-chunk" : Run First "wrote-headers" : Run First "wrote-informational" : Run First
struct SoupMessage { const char *method; guint status_code; const char *reason_phrase; SoupDataBuffer request; GHashTable *request_headers; SoupDataBuffer response; GHashTable *response_headers; SoupMessageStatus status; };
Represents an HTTP message being sent or received.
const char * |
the HTTP method |
guint |
the HTTP status code |
const char * |
the status phrase associated with status_code
|
SoupDataBuffer |
the request buffer |
GHashTable * |
the request headers |
SoupDataBuffer |
the response buffer |
GHashTable * |
the response headers |
SoupMessageStatus |
the processing status of the message |
typedef enum { SOUP_MESSAGE_STATUS_IDLE, SOUP_MESSAGE_STATUS_QUEUED, SOUP_MESSAGE_STATUS_CONNECTING, SOUP_MESSAGE_STATUS_RUNNING, SOUP_MESSAGE_STATUS_FINISHED } SoupMessageStatus;
Enum indicating the lifecycle of a SoupMessage.
The message has not yet been queued. | |
The message has been queued, but is waiting for a connection to be available. | |
The message is waiting for a specific connection to finish connecting. | |
The message is being processed. | |
The message is complete (request and response both processed). |
#define SOUP_MESSAGE_IS_STARTING(msg) (msg->status == SOUP_MESSAGE_STATUS_QUEUED || msg->status == SOUP_MESSAGE_STATUS_CONNECTING)
Tests if msg
is in a "starting" state, waiting to be sent. (More
commonly used to test if a message has been requeued after its
first attempt.)
|
a SoupMessage |
Returns : |
TRUE if msg is waiting to be sent.
|
typedef enum { SOUP_TRANSFER_UNKNOWN = 0, SOUP_TRANSFER_CHUNKED, SOUP_TRANSFER_CONTENT_LENGTH, SOUP_TRANSFER_BYTERANGES, SOUP_TRANSFER_NONE, SOUP_TRANSFER_EOF } SoupTransferEncoding;
How the length of a request or response is to be encoded.
unknown / error | |
chunked encoding (currently only supported for response) | |
Content-Length encoding | |
multipart/byteranges (Reserved for future use: NOT CURRENTLY IMPLEMENTED) | |
no body is present (which is not the same as a 0-length body, and only occurs in certain places) | |
Response body ends when the connection is closed |
typedef enum { SOUP_BUFFER_SYSTEM_OWNED = 0, SOUP_BUFFER_USER_OWNED, SOUP_BUFFER_STATIC } SoupOwnership;
Used by SoupDataBuffer (and several functions) to indicate the ownership of a buffer.
typedef struct { SoupOwnership owner; char *body; guint length; } SoupDataBuffer;
A data buffer used in several places.
SoupOwnership |
the ownership of the data |
char * |
the data itself |
guint |
length of body
|
void (*SoupMessageCallbackFn) (SoupMessage *req, gpointer user_data);
A callback function used by many SoupMessage methods.
|
the SoupMessage in question |
|
user data |
SoupMessage* soup_message_new (const char *method, const char *uri_string);
Creates a new empty SoupMessage, which will connect to uri
|
the HTTP method for the created request |
|
the destination endpoint (as a string) |
Returns : |
the new SoupMessage (or NULL if uri could not
be parsed).
|
SoupMessage* soup_message_new_from_uri (const char *method, const SoupUri *uri);
Creates a new empty SoupMessage, which will connect to uri
|
the HTTP method for the created request |
|
the destination endpoint (as a SoupUri) |
Returns : |
the new SoupMessage |
void soup_message_set_request (SoupMessage *msg, const char *content_type, SoupOwnership req_owner, char *req_body, gulong req_length);
Convenience function to set the request body of a SoupMessage
|
the message |
|
MIME Content-Type of the body |
|
the SoupOwnership of the passed data buffer. |
|
a data buffer containing the body of the message request. |
|
the byte length of req_body .
|
void soup_message_set_response (SoupMessage *msg, const char *content_type, SoupOwnership resp_owner, char *resp_body, gulong resp_length);
Convenience function to set the response body of a SoupMessage
|
the message |
|
MIME Content-Type of the body |
|
the SoupOwnership of the passed data buffer. |
|
a data buffer containing the body of the message response. |
|
the byte length of resp_body .
|
void soup_message_add_header (GHashTable *hash, const char *name, const char *value);
Adds a header with name name
and value value
to hash
. If there
was already a header with name name
, this one does not replace it,
it is merely added to it.
|
a header table (the request_headers or response_headers
field of a SoupMessage)
|
|
the header name to add |
|
the value of the new header |
const char* soup_message_get_header (GHashTable *hash, const char *name);
Finds the first header in hash
with name name
.
|
a header table (the request_headers or response_headers
field of a SoupMessage)
|
|
header name. |
Returns : |
the header's value or NULL if not found.
|
const GSList* soup_message_get_header_list (GHashTable *hash, const char *name);
Finds all headers in hash
with name name
.
|
a header table (the request_headers or response_headers
field of a SoupMessage)
|
|
header name. |
Returns : |
a (possibly empty) list of values of headers with
name name . The caller should not modify or free this list.
|
void soup_message_foreach_header (GHashTable *hash, GHFunc func, gpointer user_data);
Calls func
once for each header value in hash
. (If there are
headers will multiple values, func
will be called once on each
value.)
|
a header table (the request_headers or response_headers
field of a SoupMessage)
|
|
callback function to run for each header |
|
data to pass to func
|
void soup_message_remove_header (GHashTable *hash, const char *name);
Removes name
from hash
. If there are multiple values for name
,
they are all removed.
|
a header table (the request_headers or response_headers
field of a SoupMessage)
|
|
the header name to remove |
void soup_message_clear_headers (GHashTable *hash);
Clears hash
.
|
a header table (the request_headers or response_headers
field of a SoupMessage)
|
typedef enum { SOUP_HTTP_1_0 = 0, SOUP_HTTP_1_1 = 1 } SoupHttpVersion;
Indicates the HTTP protocol version being used.
void soup_message_set_http_version (SoupMessage *msg, SoupHttpVersion version);
Sets the HTTP version on msg
. The default version is
SOUP_HTTP_1_1
. Setting it to SOUP_HTTP_1_0
will prevent certain
functionality from being used.
|
a SoupMessage |
|
the HTTP version |
SoupHttpVersion soup_message_get_http_version (SoupMessage *msg);
Gets the HTTP version of msg
. This is the minimum of the
version from the request and the version from the response.
|
a SoupMessage |
Returns : |
the HTTP version |
const SoupUri* soup_message_get_uri (SoupMessage *msg);
Gets msg
's URI
|
a SoupMessage |
Returns : |
the URI msg is targeted for.
|
void soup_message_set_uri (SoupMessage *msg, const SoupUri *uri);
Sets msg
's URI to uri
. If msg
has already been sent and you want
to re-send it with the new URI, you need to call
soup_session_requeue_message()
.
|
a SoupMessage |
|
the new SoupUri |
typedef enum { SOUP_MESSAGE_NO_REDIRECT = (1 << 1), SOUP_MESSAGE_OVERWRITE_CHUNKS = (1 << 3), SOUP_MESSAGE_EXPECT_CONTINUE = (1 << 4) } SoupMessageFlags;
Various flags that can be set on a SoupMessage to alter its behavior.
The session should not follow redirect (3xx) responses received by this message. | |
Rather than building up the
response body in response , each new chunk should overwrite the
previous one. (This can be used if you are connecting to the
got_chunk signal or have installed a SOUP_MESSAGE_BODY_CHUNK
handler.
|
|
This will cause an "Expect: 100-continue" header to be added to the outgoing request, giving the server the opportunity to reject the message (eg, with a 401 Unauthorized) before the full request body is sent. |
void soup_message_set_flags (SoupMessage *msg, guint flags);
Sets the specified flags on msg
.
|
a SoupMessage |
|
a set of SoupMessageFlags values |
guint soup_message_get_flags (SoupMessage *msg);
Gets the flags on msg
|
a SoupMessage |
Returns : |
the flags |
void soup_message_set_status (SoupMessage *msg, guint status_code);
Sets msg
's status code to status_code
. If status_code
is a
known value, it will also set msg
's reason_phrase.
|
a SoupMessage |
|
an HTTP status code |
void soup_message_set_status_full (SoupMessage *msg, guint status_code, const char *reason_phrase);
Sets msg
's status code and reason phrase.
|
a SoupMessage |
|
an HTTP status code |
|
a description of the status |
void soup_message_add_chunk (SoupMessage *msg, SoupOwnership owner, const char *body, guint length);
Adds a chunk of response data to body
. (Note that currently
there is no way to send a request using chunked encoding.)
|
a SoupMessage |
|
the ownership of body
|
|
body data |
|
length of body
|
void soup_message_add_final_chunk (SoupMessage *msg);
Adds a final, empty chunk of response data to body
. This must
be called after adding the last real chunk, to indicate that
there is no more data.
|
a SoupMessage |
SoupDataBuffer* soup_message_pop_chunk (SoupMessage *msg);
Pops a chunk of response data from msg
's chunk list. The caller
must free chunk
itself, and must handle the data in chunk
according to its ownership
.
|
a SoupMessage |
Returns : |
the chunk, or NULL if there are no chunks left.
|
gboolean soup_message_is_keepalive (SoupMessage *msg);
Determines whether or not msg
's connection can be kept alive for
further requests after processing msg
.
|
a SoupMessage |
Returns : |
TRUE or FALSE .
|
SoupTransferEncoding soup_message_get_request_encoding (SoupMessage *msg, guint *content_length);
Gets msg
's request encoding. For an outgoing (client) request,
this is only valid after the message has been fully set up (from
the library's perspective, that means not until the message has
been queued). For an incoming (server) request, this is valid after
the request headers have been read and msg->request_headers
filled
in.
|
a SoupMessage |
|
a pointer to store the Content-Length in (or
NULL ).
|
Returns : |
the request encoding (which cannot be
SOUP_TRANSFER_UNKNOWN or SOUP_TRANSFER_EOF ). If it is
SOUP_TRANSFER_CONTENT_LENGTH , *content_length will be set to the
request body's length.
|
SoupTransferEncoding soup_message_get_response_encoding (SoupMessage *msg, guint *content_length);
Gets msg
's response encoding. For an outgoing (client) request,
this is only valid after the response headers have been read and
msg->response_headers
filled in. For an incoming (server) request,
this is valid after the server handler has run.
Note that the returned value is the encoding actually used on the
wire; this will not agree with the response headers in some cases
(eg, a HEAD response may have a Content-Length header, but will
still be considered SOUP_TRANSFER_NONE
by this function).
|
a SoupMessage |
|
a pointer to store the Content-Length in (or
NULL ).
|
Returns : |
the response encoding (which will not be
SOUP_TRANSFER_UNKNOWN ). If it is SOUP_TRANSFER_CONTENT_LENGTH ,
*content_length will be set to the response body's length.
|
typedef enum { SOUP_HANDLER_POST_REQUEST = 1, SOUP_HANDLER_PRE_BODY, SOUP_HANDLER_BODY_CHUNK, SOUP_HANDLER_POST_BODY } SoupHandlerPhase;
Indicates when a handler added with soup_message_add_handler()
or
the like will be run.
The handler should run immediately after sending the request body | |
The handler should run before reading the response body (after reading the headers). | |
The handler should run after every body
chunk is read. (See also SOUP_MESSAGE_OVERWRITE_CHUNKS .)
|
|
The handler should run after the entire message body has been read. |
void soup_message_add_handler (SoupMessage *msg, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data);
Adds a handler to msg
for all messages
|
a SoupMessage |
|
processing phase to run the handler in |
|
the handler |
|
data to pass to handler_cb
|
void soup_message_add_header_handler (SoupMessage *msg, const char *header, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data);
Adds a handler to msg
for messages containing the given response
header.
|
a SoupMessage |
|
HTTP response header to match against |
|
processing phase to run the handler in |
|
the handler |
|
data to pass to handler_cb
|
void soup_message_add_status_code_handler (SoupMessage *msg, guint status_code, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data);
Adds a handler to msg
for messages receiving the given status
code.
|
a SoupMessage |
|
HTTP status code to match against |
|
processing phase to run the handler in |
|
the handler |
|
data to pass to handler_cb
|
void soup_message_add_status_class_handler (SoupMessage *msg, SoupStatusClass status_class, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data);
Adds a handler to msg
for messages receiving a status code in
the given class.
|
a SoupMessage |
|
HTTP status code class to match against |
|
processing phase to run the handler in |
|
the handler |
|
data to pass to handler_cb
|
void soup_message_remove_handler (SoupMessage *msg, SoupHandlerPhase phase, SoupMessageCallbackFn handler_cb, gpointer user_data);
Removes all matching handlers from msg
|
a SoupMessage |
|
processing phase to run the handler in |
|
the handler |
|
data to pass to handler_cb
|
void soup_message_send_request (SoupMessage *req, SoupSocket *sock, gboolean is_via_proxy);
Begins the process of sending msg
across sock
. (If sock
is
synchronous, then soup_message_send_request()
won't return until
the response has been received.)
|
a SoupMessage |
|
the SoupSocket to send req on
|
|
TRUE if sock is a connection to a proxy server
rather than a direct connection to the desired HTTP server
|
void soup_message_read_request (SoupMessage *req, SoupSocket *sock);
Begins the process of receiving a request from sock
into req
.
|
an empty SoupServerMessage |
|
socket to receive the request on |
void soup_message_io_pause (SoupMessage *msg);
Pauses I/O on msg
. This can be used in a SoupServer handler when
you don't have the data ready to return yet, or with a client-side
message if you are not ready to process any more of the response at
this time; call soup_message_io_unpause()
to resume I/O.
|
a server-side SoupMessage |
void soup_message_io_unpause (SoupMessage *msg);
Resumes I/O on msg
. Use this to resume after calling
soup_message_io_pause()
, or after adding a new chunk to a chunked
response.
If msg
is being sent via blocking I/O, this will resume reading or
writing immediately. If msg
is using non-blocking I/O, then
reading or writing won't resume until you return to the main loop.
|
a server-side SoupMessage |
void soup_message_io_stop (SoupMessage *msg);
Immediately stops I/O on msg; if the connection would be left in an inconsistent state, it will be closed.
Note: this is a low-level function that does not cause any signals
to be emitted on msg
; it is up to the caller to make sure that
msg
doesn't get "stranded".
|
a SoupMessage |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted when all HTTP processing is finished for a message. (After read-body for client-side code, or after wrote-body for server-side code.)
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted after receiving the complete message body.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
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.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted after receiving all message headers for a message.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted after receiving a 1xx (Informational) response for a message.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted when a message is about to be re-queued.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted immediately after writing the complete body for a message.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted immediately after writing a body chunk for a message.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted immediately after writing the headers for a message.
|
the message |
|
user data set when the signal handler was connected. |
void user_function (SoupMessage *msg, gpointer user_data) : Run First
Emitted immediately after writing a 1xx (Informational) response for a message.
|
the message |
|
user data set when the signal handler was connected. |