soup.session

Module for [Session] class

Types 3

Soup session state object.

#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. It also keeps track of various global options and features that you are using.

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 class@Message 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.)

Additional #SoupSession functionality is provided by iface@SessionFeature objects, which can be added to a session with [soup.session.Session.addFeature] or [soup.session.Session.addFeatureByType] For example, class@Logger provides support for logging HTTP traffic, class@ContentDecoder provides support for compressed response handling, and class@ContentSniffer provides support for HTML5-style response body content sniffing. Additionally, subtypes of class@Auth can be added as features, to add support for additional authentication types.

All [soup.session.Session]s are created with a class@AuthManager, and support for SOUP_TYPE_AUTH_BASIC and SOUP_TYPE_AUTH_DIGEST. Additionally, sessions using the plain #SoupSession class (rather than one of its deprecated subtypes) have a class@ContentDecoder by default.

Note that all async methods will invoke their callbacks on the thread-default context at the time of the function call.

Methods
GType _gType() @property
Session self()Returns `this`, for use in `with` statements.
SessionGidBuilder builder()Get builder for [soup.session.Session] Returns: New builder object
string acceptLanguage() @propertyGet `acceptLanguage` property. Returns: If non-null, the value to use for the "Accept-Language" header on `class@Message`s sent from this session.
void acceptLanguage(string propval) @propertySet `acceptLanguage` property. Params: propval = If non-null, the value to use for the "Accept-Language" header on `class@Message`s sent from this session.
bool acceptLanguageAuto() @propertyGet `acceptLanguageAuto` property. Returns: If true, #SoupSession will automatically set the string for the "Accept-Language" header on every `class@Message` sent, based on the return value of `fun...
void acceptLanguageAuto(bool propval) @propertySet `acceptLanguageAuto` property. Params: propval = If true, #SoupSession will automatically set the string for the "Accept-Language" header on every `class@Message` sent, based on the return valu...
uint idleTimeout() @propertyGet `idleTimeout` property. Returns: Connection lifetime (in seconds) when idle. Any connection left idle longer than this will be closed.
void idleTimeout(uint propval) @propertySet `idleTimeout` property. Params: propval = Connection lifetime (in seconds) when idle. Any connection left idle longer than this will be closed.
gio.inet_socket_address.InetSocketAddress localAddress() @propertyGet `localAddress` property. Returns: Sets the [gio.inetsocketaddress.InetSocketAddress] to use for the client side of the connection.
int maxConns() @propertyGet `maxConns` property. Returns: The maximum number of connections that the session can open at once.
int maxConnsPerHost() @propertyGet `maxConnsPerHost` property. Returns: The maximum number of connections that the session can open at once to a given host.
gio.proxy_resolver.ProxyResolver proxyResolver() @propertyGet `proxyResolver` property. Returns: A [gio.proxy_resolver.ProxyResolver] to use with this session.
void proxyResolver(gio.proxy_resolver.ProxyResolver propval) @propertySet `proxyResolver` property. Params: propval = A [gio.proxy_resolver.ProxyResolver] to use with this session.
gio.socket_connectable.SocketConnectable remoteConnectable() @propertyGet `remoteConnectable` property. Returns: Sets a socket to make outgoing connections on. This will override the default behaviour of opening TCP/IP sockets to the hosts specified in the URIs.
uint timeout() @propertyGet `timeout` property. Returns: The timeout (in seconds) for socket I/O operations (including connecting to a server, and waiting for a reply to an HTTP request).
void timeout(uint propval) @propertySet `timeout` property. Params: propval = The timeout (in seconds) for socket I/O operations (including connecting to a server, and waiting for a reply to an HTTP request).
gio.tls_database.TlsDatabase tlsDatabase() @propertyGet `tlsDatabase` property. Returns: Sets the [gio.tls_database.TlsDatabase] to use for validating SSL/TLS certificates.
void tlsDatabase(gio.tls_database.TlsDatabase propval) @propertySet `tlsDatabase` property. Params: propval = Sets the [gio.tls_database.TlsDatabase] to use for validating SSL/TLS certificates.
gio.tls_interaction.TlsInteraction tlsInteraction() @propertyGet `tlsInteraction` property. Returns: A [gio.tlsinteraction.TlsInteraction] object that will be passed on to any [gio.tlsconnection.TlsConnection]s created by the session.
void tlsInteraction(gio.tls_interaction.TlsInteraction propval) @propertySet `tlsInteraction` property. Params: propval = A [gio.tlsinteraction.TlsInteraction] object that will be passed on to any [gio.tlsconnection.TlsConnection]s created by the session.
string userAgent() @propertyGet `userAgent` property. Returns: User-Agent string.
void userAgent(string propval) @propertySet `userAgent` property. Params: propval = User-Agent string.
void abort()Cancels all pending requests in session and closes all idle persistent connections.
void addFeature(soup.session_feature.SessionFeature feature)Adds feature's functionality to session. You cannot add multiple features of the same `aliasGLib.Type` to a session.
void addFeatureByType(gobject.types.GType featureType)If featuretype is the type of a class that implements `ifaceSessionFeature`, this creates a new feature of that type and adds it to session as with [soup.session.Session.addFeature]. You can use th...
string getAcceptLanguage()Get the value used by session for the "Accept-Language" header on new requests. Returns: the accept language string
bool getAcceptLanguageAuto()Gets whether session automatically sets the "Accept-Language" header on new requests. Returns: true if session sets "Accept-Language" header automatically, or false otherwise.
soup.message.Message getAsyncResultMessage(gio.async_result.AsyncResult result)Gets the `classMessage` of the result asynchronous operation This is useful to get the `classMessage` of an asynchronous operation started by session from its [gio.types.AsyncReadyCallback].
soup.session_feature.SessionFeature getFeature(gobject.types.GType featureType)Gets the feature in session of type feature_type.
soup.session_feature.SessionFeature getFeatureForMessage(gobject.types.GType featureType, soup.message.Message msg)Gets the feature in session of type feature_type, provided that it is not disabled for msg.
uint getIdleTimeout()Get the timeout in seconds for idle connection lifetime currently used by session. Returns: the timeout in seconds
gio.inet_socket_address.InetSocketAddress getLocalAddress()Get the [gio.inetsocketaddress.InetSocketAddress] to use for the client side of connections in session. Returns: a #GInetSocketAddress
uint getMaxConns()Get the maximum number of connections that session can open at once. Returns: the maximum number of connections
uint getMaxConnsPerHost()Get the maximum number of connections that session can open at once to a given host. Returns: the maximum number of connections per host
gio.proxy_resolver.ProxyResolver getProxyResolver()Get the [gio.proxy_resolver.ProxyResolver] currently used by session. Returns: a #GProxyResolver or null if proxies are disabled in session
gio.socket_connectable.SocketConnectable getRemoteConnectable()Gets the remote connectable if one set. Returns: the #GSocketConnectable
uint getTimeout()Get the timeout in seconds for socket I/O operations currently used by session. Returns: the timeout in seconds
gio.tls_database.TlsDatabase getTlsDatabase()Get the [gio.tls_database.TlsDatabase] currently used by session. Returns: a #GTlsDatabase
gio.tls_interaction.TlsInteraction getTlsInteraction()Get the [gio.tls_interaction.TlsInteraction] currently used by session. Returns: a #GTlsInteraction
string getUserAgent()Get the value used by session for the "User-Agent" header on new requests. Returns: the user agent string
bool hasFeature(gobject.types.GType featureType)Tests if session has at a feature of type feature_type (which can be the type of either a `ifaceSessionFeature`, or else a subtype of some class managed by another feature, such as `classAuth`).
void preconnectAsync(soup.message.Message msg, int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Start a preconnection to msg.
bool preconnectFinish(gio.async_result.AsyncResult result)Complete a preconnect async operation started with [soup.session.Session.preconnectAsync].
void removeFeature(soup.session_feature.SessionFeature feature)Removes feature's functionality from session.
void removeFeatureByType(gobject.types.GType featureType)Removes all features of type featuretype (or any subclass of featuretype) from session.
gio.input_stream.InputStream send(soup.message.Message msg, gio.cancellable.Cancellable cancellable = null)Synchronously sends msg and waits for the beginning of a response.
glib.bytes.Bytes sendAndRead(soup.message.Message msg, gio.cancellable.Cancellable cancellable = null)Synchronously sends msg and reads the response body.
void sendAndReadAsync(soup.message.Message msg, int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Asynchronously sends msg and reads the response body.
glib.bytes.Bytes sendAndReadFinish(gio.async_result.AsyncResult result)Gets the response to a [soup.session.Session.sendAndReadAsync].
ptrdiff_t sendAndSplice(soup.message.Message msg, gio.output_stream.OutputStream outStream, gio.types.OutputStreamSpliceFlags flags, gio.cancellable.Cancellable cancellable = null)Synchronously sends msg and splices the response body stream into out_stream.
void sendAndSpliceAsync(soup.message.Message msg, gio.output_stream.OutputStream outStream, gio.types.OutputStreamSpliceFlags flags, int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Asynchronously sends msg and splices the response body stream into out_stream. When callback is called, then either msg has been sent and its response body spliced, or else an error has occurred.
ptrdiff_t sendAndSpliceFinish(gio.async_result.AsyncResult result)Gets the response to a [soup.session.Session.sendAndSpliceAsync].
void sendAsync(soup.message.Message msg, int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Asynchronously sends msg and waits for the beginning of a response.
gio.input_stream.InputStream sendFinish(gio.async_result.AsyncResult result)Gets the response to a [soup.session.Session.sendAsync] call.
void setAcceptLanguage(string acceptLanguage)Set the value to use for the "Accept-Language" header on `classMessage`s sent from session.
void setAcceptLanguageAuto(bool acceptLanguageAuto)Set whether session will automatically set the "Accept-Language" header on requests using a value generated from system languages based on `funcGLib.getlanguagenames`.
void setIdleTimeout(uint timeout)Set a timeout in seconds for idle connection lifetime to be used by session on new connections.
void setProxyResolver(gio.proxy_resolver.ProxyResolver proxyResolver = null)Set a [gio.proxy_resolver.ProxyResolver] to be used by session on new connections.
void setTimeout(uint timeout)Set a timeout in seconds for socket I/O operations to be used by session on new connections.
void setTlsDatabase(gio.tls_database.TlsDatabase tlsDatabase = null)Set a `classGIo.TlsDatabase` to be used by session on new connections.
void setTlsInteraction(gio.tls_interaction.TlsInteraction tlsInteraction = null)Set a [gio.tls_interaction.TlsInteraction] to be used by session on new connections.
void setUserAgent(string userAgent)Set the value to use for the "User-Agent" header on `classMessage`s sent from session.
void websocketConnectAsync(soup.message.Message msg, string origin, string[] protocols, int ioPriority, gio.cancellable.Cancellable cancellable = null, gio.types.AsyncReadyCallback callback = null)Asynchronously creates a `classWebsocketConnection` to communicate with a remote server.
soup.websocket_connection.WebsocketConnection websocketConnectFinish(gio.async_result.AsyncResult result)Gets the `classWebsocketConnection` response to a [soup.session.Session.websocketConnectAsync] call.
gulong connectRequestQueued(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.message.Message))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.session.Session))) && Parameters!T.length < 3)Connect to `RequestQueued` signal.
gulong connectRequestUnqueued(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.message.Message))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : soup.session.Session))) && Parameters!T.length < 3)Connect to `RequestUnqueued` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a #SoupSession with the default options. Returns: the new session.
Methods
T acceptLanguage(string propval)Set `acceptLanguage` property. Params: propval = If non-null, the value to use for the "Accept-Language" header on `class@Message`s sent from this session.
T acceptLanguageAuto(bool propval)Set `acceptLanguageAuto` property. Params: propval = If true, #SoupSession will automatically set the string for the "Accept-Language" header on every `class@Message` sent, based on the return valu...
T idleTimeout(uint propval)Set `idleTimeout` property. Params: propval = Connection lifetime (in seconds) when idle. Any connection left idle longer than this will be closed.
T localAddress(gio.inet_socket_address.InetSocketAddress propval)Set `localAddress` property. Params: propval = Sets the [gio.inetsocketaddress.InetSocketAddress] to use for the client side of the connection.
T maxConns(int propval)Set `maxConns` property. Params: propval = The maximum number of connections that the session can open at once. Returns: Builder instance for fluent chaining
T maxConnsPerHost(int propval)Set `maxConnsPerHost` property. Params: propval = The maximum number of connections that the session can open at once to a given host. Returns: Builder instance for fluent chaining
T proxyResolver(gio.proxy_resolver.ProxyResolver propval)Set `proxyResolver` property. Params: propval = A [gio.proxy_resolver.ProxyResolver] to use with this session.
T remoteConnectable(gio.socket_connectable.SocketConnectable propval)Set `remoteConnectable` property. Params: propval = Sets a socket to make outgoing connections on. This will override the default behaviour of opening TCP/IP sockets to the hosts specified in the U...
T timeout(uint propval)Set `timeout` property. Params: propval = The timeout (in seconds) for socket I/O operations (including connecting to a server, and waiting for a reply to an HTTP request).
T tlsDatabase(gio.tls_database.TlsDatabase propval)Set `tlsDatabase` property. Params: propval = Sets the [gio.tls_database.TlsDatabase] to use for validating SSL/TLS certificates.
T tlsInteraction(gio.tls_interaction.TlsInteraction propval)Set `tlsInteraction` property. Params: propval = A [gio.tlsinteraction.TlsInteraction] object that will be passed on to any [gio.tlsconnection.TlsConnection]s created by the session.
T userAgent(string propval)Set `userAgent` property. Params: propval = User-Agent string.

Fluent builder for [soup.session.Session]

Methods