Class Session
- All Implemented Interfaces:
Proxy
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 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
SessionFeature
objects, which can be added to a session with
addFeature(org.gnome.soup.SessionFeature)
or addFeatureByType(org.gnome.glib.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 SoupSession
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Session.Builder<B extends Session.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theRequestQueuedCallback
callback.static interface
Functional interface declaration of theRequestUnqueuedCallback
callback.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionSession()
Creates aSoupSession
with the default options.Session
(MemorySegment address) Create a Session proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Cancels all pending requests in this Session and closes all idle persistent connections.void
addFeature
(SessionFeature feature) Addsfeature
's functionality to this Session.void
addFeatureByType
(Type featureType) IffeatureType
is the type of a class that implementsSessionFeature
, this creates a new feature of that type and adds it to this Session as withaddFeature(org.gnome.soup.SessionFeature)
.protected Session
asParent()
Returns this instance as if it were its parent type.static Session.Builder
<? extends Session.Builder> builder()
ASession.Builder
object constructs aSession
with the specified properties.void
emitRequestQueued
(Message msg) Emits the "request-queued" signal.void
Emits the "request-unqueued" signal.Get the value used by this Session for the "Accept-Language" header on new requests.boolean
Gets whether this Session automatically sets the "Accept-Language" header on new requests.getAsyncResultMessage
(AsyncResult result) getFeature
(Type featureType) Gets the feature in this Session of typefeatureType
.getFeatureForMessage
(Type featureType, Message msg) Gets the feature in this Session of typefeatureType
, provided that it is not disabled formsg
.int
Get the timeout in seconds for idle connection lifetime currently used by this Session.Get theInetSocketAddress
to use for the client side of connections in this Session.int
Get the maximum number of connections that this Session can open at once.int
Get the maximum number of connections that this Session can open at once to a given host.static MemoryLayout
The memory layout of the native struct.Get theProxyResolver
currently used by this Session.Gets the remote connectable if one set.int
Get the timeout in seconds for socket I/O operations currently used by this Session.Get theTlsDatabase
currently used by this Session.Get theTlsInteraction
currently used by this Session.static Type
getType()
Get the GType of the Session classGet the value used by this Session for the "User-Agent" header on new requests.boolean
hasFeature
(Type featureType) Tests if this Session has at a feature of typefeatureType
(which can be the type of either aSessionFeature
, or else a subtype of some class managed by another feature, such asAuth
).Emitted when a request is queued onsession
.Emitted when a request is removed fromsession
's queue, indicating thatsession
is done with it.void
preconnectAsync
(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Start a preconnection tomsg
.boolean
preconnectFinish
(AsyncResult result) Complete a preconnect async operation started withpreconnectAsync(org.gnome.soup.Message, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.void
removeFeature
(SessionFeature feature) Removesfeature
's functionality from this Session.void
removeFeatureByType
(Type featureType) Removes all features of typefeatureType
(or any subclass offeatureType
) from this Session.protected void
requestQueued
(Message msg) protected void
requestUnqueued
(Message msg) send
(Message msg, @Nullable Cancellable cancellable) Synchronously sendsmsg
and waits for the beginning of a response.sendAndRead
(Message msg, @Nullable Cancellable cancellable) Synchronously sendsmsg
and reads the response body.void
sendAndReadAsync
(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and reads the response body.sendAndReadFinish
(AsyncResult result) long
sendAndSplice
(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, @Nullable Cancellable cancellable) Synchronously sendsmsg
and splices the response body stream intooutStream
.long
sendAndSplice
(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, @Nullable Cancellable cancellable) Synchronously sendsmsg
and splices the response body stream intooutStream
.void
sendAndSpliceAsync
(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and splices the response body stream intooutStream
.void
sendAndSpliceAsync
(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and splices the response body stream intooutStream
.long
sendAndSpliceFinish
(AsyncResult result) void
sendAsync
(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and waits for the beginning of a response.sendFinish
(AsyncResult result) Gets the response to asendAsync(org.gnome.soup.Message, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
call.void
setAcceptLanguage
(String acceptLanguage) Set the value to use for the "Accept-Language" header onMessage
s sent from this Session.void
setAcceptLanguageAuto
(boolean acceptLanguageAuto) Set whether this Session will automatically set the "Accept-Language" header on requests using a value generated from system languages based onGLib.getLanguageNames()
.void
setIdleTimeout
(int timeout) Set a timeout in seconds for idle connection lifetime to be used by this Session on new connections.void
setProxyResolver
(@Nullable ProxyResolver proxyResolver) Set aProxyResolver
to be used by this Session on new connections.void
setTimeout
(int timeout) Set a timeout in seconds for socket I/O operations to be used by this Session on new connections.void
setTlsDatabase
(@Nullable TlsDatabase tlsDatabase) Set aTlsDatabase
to be used by this Session on new connections.void
setTlsInteraction
(@Nullable TlsInteraction tlsInteraction) Set aTlsInteraction
to be used by this Session on new connections.void
setUserAgent
(String userAgent) Set the value to use for the "User-Agent" header onMessage
s sent from this Session.void
websocketConnectAsync
(Message msg, @Nullable String origin, @Nullable String[] protocols, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously creates aWebsocketConnection
to communicate with a remote server.websocketConnectFinish
(AsyncResult result) static Session
withOptions
(String optname1, Object... varargs) Creates aSoupSession
with the specified options.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Session
Create a Session proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Session
Creates aSoupSession
with the default options.- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
withOptions
Creates aSoupSession
with the specified options.- Parameters:
optname1
- name of first property to setvarargs
- value ofoptname1
, followed by additional property/value pairs- Returns:
- the new session.
- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
abort
public void abort()Cancels all pending requests in this Session and closes all idle persistent connections. -
addFeature
Addsfeature
's functionality to this Session. You cannot add multiple features of the sameGObject.Type
to a session.See the main
SoupSession
documentation for information on what features are present in sessions by default.- Parameters:
feature
- an object that implementsSoupSessionFeature
-
addFeatureByType
IffeatureType
is the type of a class that implementsSessionFeature
, this creates a new feature of that type and adds it to this Session as withaddFeature(org.gnome.soup.SessionFeature)
. You can use this when you don't need to customize the new feature in any way. Adding multiple features of the samefeatureType
is not allowed.If
featureType
is not aSessionFeature
type, this gives each existing feature on this Session the chance to acceptfeatureType
as a "subfeature". This can be used to add newAuth
types, for instance.See the main
SoupSession
documentation for information on what features are present in sessions by default.- Parameters:
featureType
- aGType
-
getAcceptLanguage
Get the value used by this Session for the "Accept-Language" header on new requests.- Returns:
- the accept language string
-
getAcceptLanguageAuto
public boolean getAcceptLanguageAuto()Gets whether this Session automatically sets the "Accept-Language" header on new requests.- Returns:
true
if this Session sets "Accept-Language" header automatically, orfalse
otherwise.
-
getAsyncResultMessage
Gets theMessage
of theresult
asynchronous operation This is useful to get theMessage
of an asynchronous operation started by this Session from itsGio.AsyncReadyCallback
.- Parameters:
result
- theGAsyncResult
passed to your callback- Returns:
- a
SoupMessage
ornull
ifresult
is not a valid this Session async operation result.
-
getFeature
Gets the feature in this Session of typefeatureType
.- Parameters:
featureType
- theGType
of the feature to get- Returns:
- a
SoupSessionFeature
, ornull
. The feature is owned by this Session.
-
getFeatureForMessage
Gets the feature in this Session of typefeatureType
, provided that it is not disabled formsg
.- Parameters:
featureType
- theGType
of the feature to getmsg
- aSoupMessage
- Returns:
- a
SoupSessionFeature
. The feature is owned by this Session.
-
getIdleTimeout
public int getIdleTimeout()Get the timeout in seconds for idle connection lifetime currently used by this Session.- Returns:
- the timeout in seconds
-
getLocalAddress
Get theInetSocketAddress
to use for the client side of connections in this Session.- Returns:
- a
GInetSocketAddress
-
getMaxConns
public int getMaxConns()Get the maximum number of connections that this Session can open at once.- Returns:
- the maximum number of connections
-
getMaxConnsPerHost
public int getMaxConnsPerHost()Get the maximum number of connections that this Session can open at once to a given host.- Returns:
- the maximum number of connections per host
-
getProxyResolver
Get theProxyResolver
currently used by this Session.- Returns:
- a
GProxyResolver
ornull
if proxies are disabled in this Session
-
getRemoteConnectable
Gets the remote connectable if one set.- Returns:
- the
GSocketConnectable
-
getTimeout
public int getTimeout()Get the timeout in seconds for socket I/O operations currently used by this Session.- Returns:
- the timeout in seconds
-
getTlsDatabase
Get theTlsDatabase
currently used by this Session.- Returns:
- a
GTlsDatabase
-
getTlsInteraction
Get theTlsInteraction
currently used by this Session.- Returns:
- a
GTlsInteraction
-
getUserAgent
Get the value used by this Session for the "User-Agent" header on new requests.- Returns:
- the user agent string
-
hasFeature
Tests if this Session has at a feature of typefeatureType
(which can be the type of either aSessionFeature
, or else a subtype of some class managed by another feature, such asAuth
).- Parameters:
featureType
- theGType
of the class of features to check for- Returns:
true
orfalse
-
preconnectAsync
public void preconnectAsync(Message msg, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Start a preconnection tomsg
.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 givenmsg
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.
- Parameters:
msg
- aSoupMessage
ioPriority
- the I/O priority of the requestcancellable
- aGCancellable
callback
- the callback to invoke when the operation finishes
-
preconnectFinish
Complete a preconnect async operation started withpreconnectAsync(org.gnome.soup.Message, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.- Parameters:
result
- theGAsyncResult
passed to your callback- Returns:
true
if the preconnect succeeded, orfalse
in case of error.- Throws:
GErrorException
- seeGError
-
removeFeature
Removesfeature
's functionality from this Session.- Parameters:
feature
- a feature that has previously been added to this Session
-
removeFeatureByType
Removes all features of typefeatureType
(or any subclass offeatureType
) from this Session.- Parameters:
featureType
- aGType
-
send
public InputStream send(Message msg, @Nullable @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmsg
and waits for the beginning of a response.On success, a
InputStream
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-
null
,cancellable
can be used to cancel the request;send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
will return aIOErrorEnum.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, andsend(org.gnome.soup.Message, org.gnome.gio.Cancellable)
will only return once a final response has been received.- Parameters:
msg
- aSoupMessage
cancellable
- aGCancellable
- Returns:
- a
GInputStream
for reading the response body, ornull
on error. - Throws:
GErrorException
- seeGError
-
sendAndRead
public Bytes sendAndRead(Message msg, @Nullable @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmsg
and reads the response body.On success, a
GLib.Bytes
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
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
cancellable
- aGCancellable
- Returns:
- a
GBytes
, ornull
on error. - Throws:
GErrorException
- seeGError
-
sendAndReadAsync
public void sendAndReadAsync(Message msg, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and reads the response body.When
callback
is called, then eithermsg
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. CallsendAndReadFinish(org.gnome.gio.AsyncResult)
to get aGLib.Bytes
with the response body.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
ioPriority
- the I/O priority of the requestcancellable
- aGCancellable
callback
- the callback to invoke
-
sendAndReadFinish
Gets the response to asendAndReadAsync(org.gnome.soup.Message, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.If successful, returns a
GLib.Bytes
with the response body.- Parameters:
result
- theGAsyncResult
passed to your callback- Returns:
- a
GBytes
, ornull
on error. - Throws:
GErrorException
- seeGError
-
sendAndSplice
public long sendAndSplice(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmsg
and splices the response body stream intooutStream
.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
outStream
- aGOutputStream
flags
- a set ofGOutputStreamSpliceFlags
cancellable
- aGCancellable
- Returns:
- a
gssize
containing the size of the data spliced, or -1 if an error occurred. - Throws:
GErrorException
- seeGError
-
sendAndSplice
public long sendAndSplice(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmsg
and splices the response body stream intooutStream
.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
outStream
- aGOutputStream
flags
- a set ofGOutputStreamSpliceFlags
cancellable
- aGCancellable
- Returns:
- a
gssize
containing the size of the data spliced, or -1 if an error occurred. - Throws:
GErrorException
- seeGError
-
sendAndSpliceAsync
public void sendAndSpliceAsync(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and splices the response body stream intooutStream
. Whencallback
is called, then eithermsg
has been sent and its response body spliced, or else an error has occurred.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
outStream
- aGOutputStream
flags
- a set ofGOutputStreamSpliceFlags
ioPriority
- the I/O priority of the requestcancellable
- aGCancellable
callback
- the callback to invoke
-
sendAndSpliceAsync
public void sendAndSpliceAsync(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and splices the response body stream intooutStream
. Whencallback
is called, then eithermsg
has been sent and its response body spliced, or else an error has occurred.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
outStream
- aGOutputStream
flags
- a set ofGOutputStreamSpliceFlags
ioPriority
- the I/O priority of the requestcancellable
- aGCancellable
callback
- the callback to invoke
-
sendAndSpliceFinish
Gets the response to asendAndSpliceAsync(org.gnome.soup.Message, org.gnome.gio.OutputStream, java.util.Set<org.gnome.gio.OutputStreamSpliceFlags>, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.- Parameters:
result
- theGAsyncResult
passed to your callback- Returns:
- a
gssize
containing the size of the data spliced, or -1 if an error occurred. - Throws:
GErrorException
- seeGError
-
sendAsync
public void sendAsync(Message msg, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously sendsmsg
and waits for the beginning of a response.When
callback
is called, then eithermsg
has been sent, and its response headers received, or else an error has occurred. CallsendFinish(org.gnome.gio.AsyncResult)
to get aInputStream
for reading the response body.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)
for more details on the general semantics.- Parameters:
msg
- aSoupMessage
ioPriority
- the I/O priority of the requestcancellable
- aGCancellable
callback
- the callback to invoke
-
sendFinish
Gets the response to asendAsync(org.gnome.soup.Message, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
call.If successful returns a
InputStream
that can be used to read the response body.- Parameters:
result
- theGAsyncResult
passed to your callback- Returns:
- a
GInputStream
for reading the response body, ornull
on error. - Throws:
GErrorException
- seeGError
-
setAcceptLanguage
Set the value to use for the "Accept-Language" header onMessage
s sent from this Session.If
acceptLanguage
isnull
then no "Accept-Language" will be included in requests. SeeSession:accept-language
for more information.- Parameters:
acceptLanguage
- the languages string
-
setAcceptLanguageAuto
public void setAcceptLanguageAuto(boolean acceptLanguageAuto) Set whether this Session will automatically set the "Accept-Language" header on requests using a value generated from system languages based onGLib.getLanguageNames()
.See
Session:accept-language-auto
for more information.- Parameters:
acceptLanguageAuto
- the value to set
-
setIdleTimeout
public void setIdleTimeout(int timeout) Set a timeout in seconds for idle connection lifetime to be used by this Session on new connections.See
Session:idle-timeout
for more information.- Parameters:
timeout
- a timeout in seconds
-
setProxyResolver
Set aProxyResolver
to be used by this Session on new connections.If
proxyResolver
isnull
then no proxies will be used. SeeSession:proxy-resolver
for more information.- Parameters:
proxyResolver
- aGProxyResolver
ornull
-
setTimeout
public void setTimeout(int timeout) Set a timeout in seconds for socket I/O operations to be used by this Session on new connections.See
Session:timeout
for more information.- Parameters:
timeout
- a timeout in seconds
-
setTlsDatabase
Set aTlsDatabase
to be used by this Session on new connections.If
tlsDatabase
isnull
then certificate validation will always fail. SeeSession:tls-database
for more information.- Parameters:
tlsDatabase
- aGTlsDatabase
-
setTlsInteraction
Set aTlsInteraction
to be used by this Session on new connections.If
tlsInteraction
isnull
then client certificate validation will always fail.See
Session:tls-interaction
for more information.- Parameters:
tlsInteraction
- aGTlsInteraction
-
setUserAgent
Set the value to use for the "User-Agent" header onMessage
s sent from this Session.If
userAgent
has trailing whitespace, this Session will append its own product token (eg,libsoup/3.0.0
) to the end of the header for you. IfuserAgent
isnull
then no "User-Agent" will be included in requests. SeeSession:user-agent
for more information.- Parameters:
userAgent
- the user agent string
-
websocketConnectAsync
public void websocketConnectAsync(Message msg, @Nullable @Nullable String origin, @Nullable @Nullable String[] protocols, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously creates aWebsocketConnection
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,websocketConnectFinish(org.gnome.gio.AsyncResult)
will return a newWebsocketConnection
. On failure it will return aGError
.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, andwebsocketConnectFinish(org.gnome.gio.AsyncResult)
will returnWebsocketError.NOT_WEBSOCKET
.- Parameters:
msg
-SoupMessage
indicating the WebSocket server to connect toorigin
- origin of the connectionprotocols
- anull
-terminated array of protocols supportedioPriority
- the I/O priority of the requestcancellable
- aGCancellable
callback
- the callback to invoke
-
websocketConnectFinish
Gets theWebsocketConnection
response to awebsocketConnectAsync(org.gnome.soup.Message, java.lang.String, java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
call.If successful, returns a
WebsocketConnection
that can be used to communicate with the server.- Parameters:
result
- theGAsyncResult
passed to your callback- Returns:
- a new
SoupWebsocketConnection
, ornull
on error. - Throws:
GErrorException
- seeGError
-
requestQueued
-
requestUnqueued
-
onRequestQueued
public SignalConnection<Session.RequestQueuedCallback> onRequestQueued(Session.RequestQueuedCallback handler) Emitted when a request is queued onsession
.When sending a request, first
Session::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 emitMessage::restarted
, which will then be followed by otherMessage
signals when the message is re-sent.Eventually, the message will emit
Message::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
Session::request-unqueued
to indicate that it is done with the message.To sum up:
Session::request-queued
andSession::request-unqueued
are guaranteed to be emitted exactly once, butMessage::finished
(and all of the otherMessage
signals) may be invoked multiple times for a given message.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitRequestQueued
Emits the "request-queued" signal. SeeonRequestQueued(org.gnome.soup.Session.RequestQueuedCallback)
. -
onRequestUnqueued
public SignalConnection<Session.RequestUnqueuedCallback> onRequestUnqueued(Session.RequestUnqueuedCallback handler) Emitted when a request is removed fromsession
's queue, indicating thatsession
is done with it.See
Session::request-queued
for a detailed description of the message lifecycle within a session.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitRequestUnqueued
Emits the "request-unqueued" signal. SeeonRequestUnqueued(org.gnome.soup.Session.RequestUnqueuedCallback)
. -
builder
ASession.Builder
object constructs aSession
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSession.Builder.build()
.
-