SoupSession

SoupSession — Soup session state object

Synopsis




struct              SoupSession;

void                (*SoupSessionCallback)              (SoupSession *session,
                                                         SoupMessage *msg,
                                                         gpointer user_data);
void                soup_session_queue_message          (SoupSession *session,
                                                         SoupMessage *msg,
                                                         SoupSessionCallback callback,
                                                         gpointer user_data);
void                soup_session_requeue_message        (SoupSession *session,
                                                         SoupMessage *msg);
guint               soup_session_send_message           (SoupSession *session,
                                                         SoupMessage *msg);
void                soup_session_cancel_message         (SoupSession *session,
                                                         SoupMessage *msg,
                                                         guint status_code);
void                soup_session_abort                  (SoupSession *session);

void                soup_session_pause_message          (SoupSession *session,
                                                         SoupMessage *msg);
void                soup_session_unpause_message        (SoupSession *session,
                                                         SoupMessage *msg);

GMainContext*       soup_session_get_async_context      (SoupSession *session);

#define             SOUP_SESSION_PROXY_URI
#define             SOUP_SESSION_MAX_CONNS
#define             SOUP_SESSION_MAX_CONNS_PER_HOST
#define             SOUP_SESSION_USE_NTLM
#define             SOUP_SESSION_SSL_CA_FILE
#define             SOUP_SESSION_ASYNC_CONTEXT
#define             SOUP_SESSION_TIMEOUT
#define             SOUP_SESSION_USER_AGENT

Object Hierarchy


  GObject
   +----SoupSession
         +----SoupSessionSync
         +----SoupSessionAsync

Properties


  "async-context"            gpointer              : Read / Write / Construct Only
  "max-conns"                gint                  : Read / Write
  "max-conns-per-host"       gint                  : Read / Write
  "proxy-uri"                SoupURI*              : Read / Write
  "ssl-ca-file"              gchar*                : Read / Write
  "timeout"                  guint                 : Read / Write
  "use-ntlm"                 gboolean              : Read / Write
  "user-agent"               gchar*                : Read / Write

Signals


  "authenticate"                                   : Run First
  "request-started"                                : Run First

Description

SoupSession is the object that controls client-side HTTP. A SoupSession encapsulates all of the state that libsoup is keeping on behalf of your program; cached HTTP connections, authentication information, etc.

Most applications will only need a single SoupSession; the primary reason you might need multiple sessions is if you need to have multiple independent authentication contexts. (Eg, you are connecting to a server and authenticating as two different users at different times; the easiest way to ensure that each SoupMessage is sent with the authentication information you intended is to use one session for the first user, and a second session for the other user.)

SoupSession itself is an abstract class, with two subclasses. If you are using the glib main loop, you will generally want to use SoupSessionAsync, which uses non-blocking I/O and callbacks. On the other hand, if your application is threaded and you want to do synchronous I/O in a separate thread from the UI, use SoupSessionSync.

Details

struct SoupSession

struct SoupSession;


SoupSessionCallback ()

void                (*SoupSessionCallback)              (SoupSession *session,
                                                         SoupMessage *msg,
                                                         gpointer user_data);

Prototype for the callback passed to soup_session_queue_message(), qv.

session :

the session

msg :

the message that has finished

user_data :

the data passed to soup_session_queue_message

soup_session_queue_message ()

void                soup_session_queue_message          (SoupSession *session,
                                                         SoupMessage *msg,
                                                         SoupSessionCallback callback,
                                                         gpointer user_data);

Queues the message msg for sending. All messages are processed while the glib main loop runs. If msg has been processed before, any resources related to the time it was last sent are freed.

Upon message completion, the callback specified in callback will be invoked (in the thread associated with session's async context). If after returning from this callback the message has not been requeued, msg will be unreffed.

session :

a SoupSession

msg :

the message to queue

callback :

a SoupSessionCallback which will be called after the message completes or when an unrecoverable error occurs.

user_data :

a pointer passed to callback.

soup_session_requeue_message ()

void                soup_session_requeue_message        (SoupSession *session,
                                                         SoupMessage *msg);

This causes msg to be placed back on the queue to be attempted again.

session :

a SoupSession

msg :

the message to requeue

soup_session_send_message ()

guint               soup_session_send_message           (SoupSession *session,
                                                         SoupMessage *msg);

Synchronously send msg. This call will not return until the transfer is finished successfully or there is an unrecoverable error.

msg is not freed upon return.

session :

a SoupSession

msg :

the message to send

Returns :

the HTTP status code of the response

soup_session_cancel_message ()

void                soup_session_cancel_message         (SoupSession *session,
                                                         SoupMessage *msg,
                                                         guint status_code);

Causes session to immediately finish processing msg, with a final status_code of status_code. Depending on when you cancel it, the response state may be incomplete or inconsistent.

session :

a SoupSession

msg :

the message to cancel

status_code :

status code to set on msg (generally SOUP_STATUS_CANCELLED)

soup_session_abort ()

void                soup_session_abort                  (SoupSession *session);

Cancels all pending requests in session.

session :

the session

soup_session_pause_message ()

void                soup_session_pause_message          (SoupSession *session,
                                                         SoupMessage *msg);

Pauses HTTP I/O on msg. Call soup_session_unpause_message() to resume I/O.

session :

a SoupSession

msg :

a SoupMessage currently running on session

soup_session_unpause_message ()

void                soup_session_unpause_message        (SoupSession *session,
                                                         SoupMessage *msg);

Resumes HTTP I/O on msg. Use this to resume after calling soup_sessino_pause_message().

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.

session :

a SoupSession

msg :

a SoupMessage currently running on session

soup_session_get_async_context ()

GMainContext*       soup_session_get_async_context      (SoupSession *session);

Gets session's async_context. This does not add a ref to the context, so you will need to ref it yourself if you want it to outlive its session.

session :

a SoupSession

Returns :

session's GMainContext, which may be NULL

SOUP_SESSION_PROXY_URI

#define SOUP_SESSION_PROXY_URI          "proxy-uri"


SOUP_SESSION_MAX_CONNS

#define SOUP_SESSION_MAX_CONNS          "max-conns"


SOUP_SESSION_MAX_CONNS_PER_HOST

#define SOUP_SESSION_MAX_CONNS_PER_HOST "max-conns-per-host"


SOUP_SESSION_USE_NTLM

#define SOUP_SESSION_USE_NTLM           "use-ntlm"


SOUP_SESSION_SSL_CA_FILE

#define SOUP_SESSION_SSL_CA_FILE        "ssl-ca-file"


SOUP_SESSION_ASYNC_CONTEXT

#define SOUP_SESSION_ASYNC_CONTEXT      "async-context"


SOUP_SESSION_TIMEOUT

#define SOUP_SESSION_TIMEOUT		"timeout"


SOUP_SESSION_USER_AGENT

#define SOUP_SESSION_USER_AGENT         "user-agent"

Property Details

The "async-context" property

  "async-context"            gpointer              : Read / Write / Construct Only

The GMainContext to dispatch async I/O in.


The "max-conns" property

  "max-conns"                gint                  : Read / Write

The maximum number of connections that the session can open at once.

Allowed values: >= 1

Default value: 10


The "max-conns-per-host" property

  "max-conns-per-host"       gint                  : Read / Write

The maximum number of connections that the session can open at once to a given host.

Allowed values: >= 1

Default value: 2


The "proxy-uri" property

  "proxy-uri"                SoupURI*              : Read / Write

The HTTP Proxy to use for this session.


The "ssl-ca-file" property

  "ssl-ca-file"              gchar*                : Read / Write

File containing SSL CA certificates.

Default value: NULL


The "timeout" property

  "timeout"                  guint                 : Read / Write

Value in seconds to timeout a blocking I/O.

Default value: 0


The "use-ntlm" property

  "use-ntlm"                 gboolean              : Read / Write

Whether or not to use NTLM authentication.

Default value: FALSE


The "user-agent" property

  "user-agent"               gchar*                : Read / Write

If non-NULL, the value to use for the "User-Agent" header on SoupMessages sent from this session.

RFC 2616 says: "The User-Agent request-header field contains information about the user agent originating the request. This is for statistical purposes, the tracing of protocol violations, and automated recognition of user agents for the sake of tailoring responses to avoid particular user agent limitations. User agents SHOULD include this field with requests."

The User-Agent header 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.

If you set a user_agent property that has trailing whitespace, SoupSession will append its own product token (eg, "libsoup/2.3.2") to the end of the header for you.

Default value: NULL

Signal Details

The "authenticate" signal

void                user_function                      (SoupSession *session,
                                                        SoupMessage *msg,
                                                        SoupAuth    *auth,
                                                        gboolean     retrying,
                                                        gpointer     user_data)      : Run First

Emitted when the session requires authentication. If credentials are available call soup_auth_authenticate() on auth. If these credentials fail, the signal will be emitted again, with retrying set to TRUE, which will continue until you return without calling soup_auth_authenticate() on auth.

Note that this may be emitted before msg's body has been fully read.

If you call soup_session_pause_message() on msg before returning, then you can authenticate auth asynchronously (as long as you g_object_ref() it to make sure it doesn't get destroyed), and then unpause msg when you are ready for it to continue.

session :

the session

msg :

the SoupMessage being sent

auth :

the SoupAuth to authenticate

retrying :

TRUE if this is the second (or later) attempt

user_data :

user data set when the signal handler was connected.

The "request-started" signal

void                user_function                      (SoupSession *session,
                                                        SoupMessage *msg,
                                                        SoupSocket  *socket,
                                                        gpointer     user_data)      : Run First

Emitted just before a request is sent.

session :

the session

msg :

the request being sent

socket :

the socket the request is being sent on

user_data :

user data set when the signal handler was connected.