It derives from <GObject>.
Soup session state object.
Session is the object that controls client-side HTTP. A
Session 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 Session; 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 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 Session functionality is provided by
SessionFeature objects, which can be added to a session with
Session.add_feature or Session.add_feature_by_type For
example, Logger provides support for logging HTTP traffic,
ContentDecoder provides support for compressed response handling,
and ContentSniffer provides support for HTML5-style response body
content sniffing. Additionally, subtypes of Auth can be added as
features, to add support for additional authentication types.
All <SoupSession>s are created with a
AuthManager, and support for SOUP_TYPE_AUTH_BASIC and
SOUP_TYPE_AUTH_DIGEST. Additionally, sessions using the plain
Session class (rather than one of its deprecated subtypes) have a
ContentDecoder by default.
Note that all async methods will invoke their callbacks on the thread-default context at the time of the function call.
parent-instanceIf non-#f, the value to use for the "Accept-Language" header on
Messages sent from this session.
Setting this will disable Session:accept-language-auto.
Its value is a string, or #f.
Set it with (set! (session:accept-language self) value).
If #t, Session will automatically set the string for the
"Accept-Language" header on every Message sent, based on the
return value of
get-language-names.
Setting this will override any previous value of
Session:accept-language.
Its value is a boolean.
Set it with (set! (session:accept-language-auto self) value).
Connection lifetime (in seconds) when idle. Any connection left idle longer than this will be closed.
Although you can change this property at any time, it will only affect
newly-created connections, not currently-open ones. You can call
Session.abort after setting this if you want to ensure that all
future connections will have this timeout value.
Its value is an unsigned 32-bit integer.
Set it with (set! (session:idle-timeout self) value).
Sets the <GInetSocketAddress> to use
for the client side of the connection.
Use this property if you want for instance to bind the local socket to a specific IP address.
Its value is a <GInetSocketAddress>,
or #f.
It can only be set when the object is made, with #:local-address.
The maximum number of connections that the session can open at once.
Its value is a 32-bit integer.
It can only be set when the object is made, with #:max-conns.
The maximum number of connections that the session can open at once to a given host.
Its value is a 32-bit integer.
It can only be set when the object is made, with
#:max-conns-per-host.
A <GProxyResolver> to use with this
session.
If no proxy resolver is set, then the default proxy resolver will be
used. See proxy-resolver:get-default. You can set it to
#f if you don’t want to use proxies, or set it to your own
<GProxyResolver> if you want to control
what proxies get used.
Its value is a <GProxyResolver>, or
#f.
Set it with (set! (session:proxy-resolver self) value).
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.
This function is not required for common HTTP usage, but only when
connecting to a HTTP service that is not using standard TCP/IP sockets.
An example of this is a local service that uses HTTP over UNIX-domain
sockets, in that case a
<GUnixSocketAddress> can be passed
to this function.
Its value is a <GSocketConnectable>,
or #f.
It can only be set when the object is made, with
#:remote-connectable.
The timeout (in seconds) for socket I/O operations (including connecting to a server, and waiting for a reply to an HTTP request).
Although you can change this property at any time, it will only affect
newly-created connections, not currently-open ones. You can call
Session.abort after setting this if you want to ensure that all
future connections will have this timeout value.
Not to be confused with Session:idle-timeout (which is the length
of time that idle persistent connections will be kept open).
Its value is an unsigned 32-bit integer.
Set it with (set! (session:timeout self) value).
Sets the <GTlsDatabase> to use for
validating SSL/TLS certificates.
If no certificate database is set, then the default database will be
used. See tls-backend:get-default-database.
Its value is a <GTlsDatabase>, or
#f.
Set it with (set! (session:tls-database self) value).
A <GTlsInteraction> object that will be
passed on to any <GTlsConnection>s
created by the session.
This can be used to provide client-side certificates, for example.
Its value is a <GTlsInteraction>, or
#f.
Set it with (set! (session:tls-interaction self) value).
User-Agent string.
If non-#f, the value to use for the "User-Agent" header on
Messages 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 Session:user-agent property that has trailing
whitespace, Session will append its own product token (eg,
libsoup/2.3.2) to the end of the header for you.
Its value is a string, or #f.
Set it with (set! (session:user-agent self) value).
Cancels all pending requests in self and closes all idle persistent connections.
Passed: a <SoupSession>.
the session
Adds feature’s functionality to self. You cannot add
multiple features of the same GObject.Type to a session.
See the main Session documentation for information on what
features are present in sessions by default.
Passed: a <SoupSession>.
Passed: a <SoupSessionFeature>.
an object that implements
<SoupSessionFeature>
If feature-type is the type of a class that implements
SessionFeature, this creates a new feature of that type and adds
it to self as with Session.add_feature. You can use this
when you don’t need to customize the new feature in any way. Adding
multiple features of the same feature-type is not allowed.
If feature-type is not a SessionFeature type, this gives
each existing feature on self the chance to accept
feature-type as a "subfeature". This can be used to add new
Auth types, for instance.
See the main Session documentation for information on what
features are present in sessions by default.
Passed: a <SoupSession>.
Passed: a class, or a GType number.
a GType
Get the value used by self for the "Accept-Language" header on new requests.
Passed: a <SoupSession>.
Returned: a string, or #f.
the accept language string
Gets whether self automatically sets the "Accept-Language" header on new requests.
Passed: a <SoupSession>.
Returned: a boolean.
#t if self sets "Accept-Language" header automatically, or
#f otherwise.
Gets the Message of the result asynchronous operation This
is useful to get the Message of an asynchronous operation started
by self from its
GAsyncReadyCallback.
Passed: a <SoupSession>.
Passed: a <GAsyncResult>.
the <GAsyncResult> passed to your callback
Returned: a <SoupMessage>, or #f.
a <SoupMessage> or #f if result is
not a valid self async operation result.
Gets the feature in self of type feature-type.
Passed: a <SoupSession>.
Passed: a class, or a GType number.
the GType of the feature to get
Returned: a <SoupSessionFeature>, or
#f.
a <SoupSessionFeature>, or #f. The
feature is owned by self.
Gets the feature in self of type feature-type, provided that it is not disabled for msg.
Passed: a <SoupSession>.
Passed: a class, or a GType number.
the GType of the feature to get
Passed: a <SoupMessage>.
Returned: a <SoupSessionFeature>, or
#f.
a <SoupSessionFeature>. The feature is
owned by self.
Get the timeout in seconds for idle connection lifetime currently used by self.
Passed: a <SoupSession>.
Returned: an unsigned 32-bit integer.
the timeout in seconds
Get the <GInetSocketAddress> to use
for the client side of connections in self.
Passed: a <SoupSession>.
Returned: a <GInetSocketAddress>, or
#f.
Get the maximum number of connections that self can open at once.
Passed: a <SoupSession>.
Returned: an unsigned 32-bit integer.
the maximum number of connections
Get the maximum number of connections that self can open at once to a given host.
Passed: a <SoupSession>.
Returned: an unsigned 32-bit integer.
the maximum number of connections per host
Get the <GProxyResolver> currently used
by self.
Passed: a <SoupSession>.
Returned: a <GProxyResolver>, or
#f.
a <GProxyResolver> or #f if
proxies are disabled in self
Gets the remote connectable if one set.
Passed: a <SoupSession>.
Returned: a <GSocketConnectable>, or
#f.
Get the timeout in seconds for socket I/O operations currently used by self.
Passed: a <SoupSession>.
Returned: an unsigned 32-bit integer.
the timeout in seconds
Get the <GTlsDatabase> currently used by
self.
Passed: a <SoupSession>.
Returned: a <GTlsDatabase>, or #f.
Get the <GTlsInteraction> currently
used by self.
Passed: a <SoupSession>.
Returned: a <GTlsInteraction>, or
#f.
Get the value used by self for the "User-Agent" header on new requests.
Passed: a <SoupSession>.
Returned: a string, or #f.
the user agent string
Tests if self has at a feature of type feature-type (which
can be the type of either a SessionFeature, or else a subtype of
some class managed by another feature, such as Auth).
Passed: a <SoupSession>.
Passed: a class, or a GType number.
the GType of the class of features to check for
Returned: a boolean.
#t or #f
Creates a Session with the default options.
Returned: a <SoupSession>.
the new session.
Start a preconnection to msg.
Once the connection is done, it will remain in idle state so that it can be reused by future requests. If there’s already an idle connection for the given msg host, the operation finishes successfully without creating a new connection. If a new request for the given msg host is made while the preconnect is still ongoing, the request will take the ownership of the connection and the preconnect operation will finish successfully (if there’s a connection error it will be handled by the request).
The operation finishes when the connection is done or an error occurred.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
Passed, or left out: a procedure, or #f.
the callback to invoke when the operation finishes
See GAsyncReadyCallback for how it
is called.
Not passed: guile-gi supplies it.
data for progress-callback and callback
Complete a preconnect async operation started with
Session.preconnect_async.
Passed: a <SoupSession>.
Passed: a <GAsyncResult>.
the <GAsyncResult> passed to your callback
Returned: a boolean.
#t if the preconnect succeeded, or #f in case of error.
Removes feature’s functionality from self.
Passed: a <SoupSession>.
Passed: a <SoupSessionFeature>.
a feature that has previously been added to self
Removes all features of type feature-type (or any subclass of feature-type) from self.
Passed: a <SoupSession>.
Passed: a class, or a GType number.
a GType
Synchronously sends msg and waits for the beginning of a response.
On success, a <GInputStream> will be
returned which you can use to read the response body. ("Success" here
means only that an HTTP response was received and understood; it does
not necessarily mean that a 2xx class status code was received.)
If non-#f, cancellable can be used to cancel the request;
Session.send will return a
cancelled error. Note that with requests
that have side effects (eg, POST, PUT, DELETE) it
is possible that you might cancel the request after the server acts on
it, but before it returns a response, leaving the remote resource in an
unknown state.
If msg is requeued due to a redirect or authentication, the
initial (3xx/401/407) response body will be suppressed, and
Session.send will only return once a final response has been
received.
Possible error domains include SessionError,
<GIOErrorEnum>, and
<GTlsError> which you may want to
specifically handle.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed, or left out: a <GCancellable>, or
#f.
Returned: a <GInputStream>.
a <GInputStream> for reading the response
body, or #f on error.
Synchronously sends msg and reads the response body.
On success, a <GBytes> will be returned with
the response body. This function should only be used when the resource
to be retrieved is not too long and can be stored in memory.
See Session.send for more details on the general semantics.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed, or left out: a <GCancellable>, or
#f.
Returned: a <GBytes>.
a <GBytes>, or #f on error.
Asynchronously sends msg and reads the response body.
When callback is called, then either msg has been sent, and
its response body read, or else an error has occurred. This function
should only be used when the resource to be retrieved is not too long
and can be stored in memory. Call Session.send_and_read_finish
to get a <GBytes> with the response body.
See Session.send for more details on the general semantics.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
Passed, or left out: a procedure, or #f.
the callback to invoke
See GAsyncReadyCallback for how it
is called.
Not passed: guile-gi supplies it.
data for callback
Gets the response to a Session.send_and_read_async.
If successful, returns a <GBytes> with the
response body.
Passed: a <SoupSession>.
Passed: a <GAsyncResult>.
the <GAsyncResult> passed to your callback
Returned: a <GBytes>.
a <GBytes>, or #f on error.
Synchronously sends msg and splices the response body stream into out-stream.
See Session.send for more details on the general semantics.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed: a <GOutputStream>.
Passed: a
<GOutputStreamSpliceFlags>, or
a list of its symbols, or one of them.
a set of
<GOutputStreamSpliceFlags>
Passed, or left out: a <GCancellable>, or
#f.
Returned: a 64-bit integer.
a gssize containing the size of the data spliced, or -1 if an
error occurred.
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.
See Session.send for more details on the general semantics.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed: a <GOutputStream>.
Passed: a
<GOutputStreamSpliceFlags>, or
a list of its symbols, or one of them.
a set of
<GOutputStreamSpliceFlags>
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
Passed, or left out: a procedure, or #f.
the callback to invoke
See GAsyncReadyCallback for how it
is called.
Not passed: guile-gi supplies it.
data for callback
Gets the response to a Session.send_and_splice_async.
Passed: a <SoupSession>.
Passed: a <GAsyncResult>.
the <GAsyncResult> passed to your callback
Returned: a 64-bit integer.
a gssize containing the size of the data spliced, or -1 if an
error occurred.
Asynchronously sends msg and waits for the beginning of a response.
When callback is called, then either msg has been sent, and
its response headers received, or else an error has occurred. Call
Session.send_finish to get a
<GInputStream> for reading the response
body.
See Session.send for more details on the general semantics.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
Passed, or left out: a procedure, or #f.
the callback to invoke
See GAsyncReadyCallback for how it
is called.
Not passed: guile-gi supplies it.
data for callback
Gets the response to a Session.send_async call.
If successful returns a <GInputStream>
that can be used to read the response body.
Passed: a <SoupSession>.
Passed: a <GAsyncResult>.
the <GAsyncResult> passed to your callback
Returned: a <GInputStream>.
a <GInputStream> for reading the response
body, or #f on error.
Set the value to use for the "Accept-Language" header on Messages
sent from self.
If accept-language is #f then no "Accept-Language" will be
included in requests. See Session:accept-language for more
information.
Passed: a <SoupSession>.
Passed: a string.
the languages string
Set whether self will automatically set the "Accept-Language"
header on requests using a value generated from system languages based
on get-language-names.
See Session:accept-language-auto for more information.
Passed: a <SoupSession>.
Passed: a boolean.
the value to set
Set a timeout in seconds for idle connection lifetime to be used by self on new connections.
See Session:idle-timeout for more information.
Passed: a <SoupSession>.
Passed: an unsigned 32-bit integer.
a timeout in seconds
Set a <GProxyResolver> to be used by
self on new connections.
If proxy-resolver is #f then no proxies will be used. See
Session:proxy-resolver for more information.
Passed: a <SoupSession>.
Passed, or left out: a <GProxyResolver>,
or #f.
a <GProxyResolver> or #f
Set a timeout in seconds for socket I/O operations to be used by self on new connections.
See Session:timeout for more information.
Passed: a <SoupSession>.
Passed: an unsigned 32-bit integer.
a timeout in seconds
Set a <GTlsDatabase> to be used by
self on new connections.
If tls-database is #f then certificate validation will
always fail. See Session:tls-database for more information.
Passed: a <SoupSession>.
Passed, or left out: a <GTlsDatabase>, or
#f.
Set a <GTlsInteraction> to be used by
self on new connections.
If tls-interaction is #f then client certificate validation
will always fail.
See Session:tls-interaction for more information.
Passed: a <SoupSession>.
Passed, or left out: a
<GTlsInteraction>, or #f.
Set the value to use for the "User-Agent" header on Messages sent
from self.
If user-agent has trailing whitespace, self will append its
own product token (eg, libsoup/3.0.0) to the end of the header
for you. If user-agent is #f then no "User-Agent" will be
included in requests. See Session:user-agent for more
information.
Passed: a <SoupSession>.
Passed: a string.
the user agent string
Asynchronously creates a WebsocketConnection to communicate with
a remote server.
All necessary WebSocket-related headers will be added to msg, and it will then be sent and asynchronously processed normally (including handling of redirection and HTTP authentication).
If the server returns "101 Switching Protocols", then msg’s status
code and response headers will be updated, and then the WebSocket
handshake will be completed. On success,
Session.websocket_connect_finish will return a new
WebsocketConnection. On failure it will return a
<GError>.
If the server returns a status other than "101 Switching Protocols",
then msg will contain the complete response headers and body from
the server’s response, and Session.websocket_connect_finish will
return not-websocket.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
<SoupMessage> indicating the WebSocket server to
connect to
Passed: a string, or #f.
origin of the connection
Passed: a list or vector, each a string, or #f.
a #f-terminated array of protocols supported
Passed: a 32-bit integer.
the I/O priority of the request
Passed, or left out: a <GCancellable>, or
#f.
Passed, or left out: a procedure, or #f.
the callback to invoke
See GAsyncReadyCallback for how it
is called.
Not passed: guile-gi supplies it.
data for callback
Gets the WebsocketConnection response to a
Session.websocket_connect_async call.
If successful, returns a WebsocketConnection that can be used to
communicate with the server.
Passed: a <SoupSession>.
Passed: a <GAsyncResult>.
the <GAsyncResult> passed to your callback
Returned: a <SoupWebsocketConnection>.
a new <SoupWebsocketConnection>, or
#f on error.
Connect a handler with (connect object session:request-queued
handler). It is called as (handler self msg).
Emitted when a request is queued on session.
When sending a request, first "request-queued" is emitted,
indicating that the session has become aware of the request.
After a connection is available to send the request various
Message signals are emitted as the message is processed. If the
message is requeued, it will emit "restarted", which will then be
followed by other Message signals when the message is re-sent.
Eventually, the message will emit "finished". Normally, this
signals the completion of message processing. However, it is possible
that the application will requeue the message from the "finished"
handler. In that case the process will loop back.
Eventually, a message will reach "finished" and not be requeued. At
that point, the session will emit "request-unqueued" to indicate
that it is done with the message.
To sum up: "request-queued" and "request-unqueued" are
guaranteed to be emitted exactly once, but "finished" (and all of
the other Message signals) may be invoked multiple times for a
given message.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
the request that was queued
Connect a handler with (connect object session:request-unqueued
handler). It is called as (handler self msg).
Emitted when a request is removed from session’s queue, indicating that session is done with it.
See "request-queued" for a detailed description of the message
lifecycle within a session.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
the request that was unqueued
To override it in a new class, give register-type #:vfuncs
`((request-queued . ,procedure)). The procedure is called as
(procedure self msg).
Passed: the class whose implementation to call:
<SoupSession>, or a class that derives from it, or
its GType number.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.
To override it in a new class, give register-type #:vfuncs
`((request-unqueued . ,procedure)). The procedure is called as
(procedure self msg).
Passed: the class whose implementation to call:
<SoupSession>, or a class that derives from it, or
its GType number.
Passed: a <SoupSession>.
Passed: a <SoupMessage>.