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 SoupSessions 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
Nested ClassesModifier and TypeClassDescriptionstatic classSession.Builder<B extends Session.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theRequestQueuedCallbackcallback.static interfaceFunctional interface declaration of theRequestUnqueuedCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionSession()Creates a new Session.Session(MemorySegment address) Create a Session proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Cancels all pending requests in this Session and closes all idle persistent connections.voidaddFeature(SessionFeature feature) Addsfeature'sfunctionality tosession.You cannot add multiple features of the sameGObject.Typeto a session.voidaddFeatureByType(Type featureType) IffeatureTypeis 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 SessionasParent()Returns this instance as if it were its parent type.static Session.Builder<? extends Session.Builder> builder()ASession.Builderobject constructs aSessionwith the specified properties.voidemitRequestQueued(@Nullable Message msg) Emits the "request-queued" signal.voidemitRequestUnqueued(@Nullable Message msg) Emits the "request-unqueued" signal.@Nullable StringGet the value used by this Session for the "Accept-Language" header on new requests.booleanGets whether this Session automatically sets the "Accept-Language" header on new requests.@Nullable MessagegetAsyncResultMessage(AsyncResult result) @Nullable SessionFeaturegetFeature(Type featureType) Gets the feature in this Session of typefeatureType.@Nullable SessionFeaturegetFeatureForMessage(Type featureType, Message msg) Gets the feature in this Session of typefeatureType,provided that it is not disabled formsg.intGet the timeout in seconds for idle connection lifetime currently used bysession.@Nullable InetSocketAddressGet theInetSocketAddressto use for the client side of connections insession.intGet the maximum number of connections that this Session can open at once.intGet the maximum number of connections that this Session can open at once to a given host.static MemoryLayoutThe memory layout of the native struct.@Nullable ProxyResolverGet theProxyResolvercurrently used bysession.@Nullable SocketConnectableGets the remote connectable if one set.intGet the timeout in seconds for socket I/O operations currently used bysession.@Nullable TlsDatabaseGet theTlsDatabasecurrently used bysession.@Nullable TlsInteractionGet theTlsInteractioncurrently used bysession.static @Nullable TypegetType()Get the GType of the Session class@Nullable StringGet the value used by this Session for the "User-Agent" header on new requests.booleanhasFeature(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'squeue, indicating thatsessionis done with it.voidpreconnectAsync(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Start a preconnection tomsg.booleanpreconnectFinish(AsyncResult result) Complete a preconnect async operation started withpreconnectAsync(org.gnome.soup.Message, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback).voidremoveFeature(SessionFeature feature) Removesfeature'sfunctionality fromsession.voidremoveFeatureByType(Type featureType) Removes all features of typefeatureType(or any subclass offeatureType)fromsession.protected voidrequestQueued(Message msg) protected voidrequestUnqueued(Message msg) send(Message msg, @Nullable Cancellable cancellable) Synchronously sendsmsgand waits for the beginning of a response.byte[]sendAndRead(Message msg, @Nullable Cancellable cancellable) Synchronously sendsmsgand reads the response body.voidsendAndReadAsync(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand reads the response body.byte[]sendAndReadFinish(AsyncResult result) longsendAndSplice(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, @Nullable Cancellable cancellable) Synchronously sendsmsgand splices the response body stream intooutStream.longsendAndSplice(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, @Nullable Cancellable cancellable) Synchronously sendsmsgand splices the response body stream intooutStream.voidsendAndSpliceAsync(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand splices the response body stream intooutStream.Whencallbackis called, then eithermsghas been sent and its response body spliced, or else an error has occurred.voidsendAndSpliceAsync(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand splices the response body stream intooutStream.Whencallbackis called, then eithermsghas been sent and its response body spliced, or else an error has occurred.longsendAndSpliceFinish(AsyncResult result) voidsendAsync(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand 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.voidsetAcceptLanguage(String acceptLanguage) Set the value to use for the "Accept-Language" header onMessages sent fromsession.voidsetAcceptLanguageAuto(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().voidsetIdleTimeout(int timeout) Set a timeout in seconds for idle connection lifetime to be used by this Session on new connections.voidsetProxyResolver(@Nullable ProxyResolver proxyResolver) Set aProxyResolverto be used by this Session on new connections.voidsetTimeout(int timeout) Set a timeout in seconds for socket I/O operations to be used by this Session on new connections.voidsetTlsDatabase(@Nullable TlsDatabase tlsDatabase) Set aTlsDatabaseto be used by this Session on new connections.voidsetTlsInteraction(@Nullable TlsInteraction tlsInteraction) Set aTlsInteractionto be used by this Session on new connections.voidsetUserAgent(String userAgent) Set the value to use for the "User-Agent" header onMessages sent fromsession.voidwebsocketConnectAsync(Message msg, @Nullable String origin, @Nullable String @Nullable [] protocols, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously creates aWebsocketConnectionto communicate with a remote server.websocketConnectFinish(AsyncResult result) static SessionwithOptions(String optname1, Object... varargs) Creates aSoupSessionwith 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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
public Session()Creates a new Session.
-
-
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 Javasuperkeyword, 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
-
abort
public void abort()Cancels all pending requests in this Session and closes all idle persistent connections. -
addFeature
Addsfeature'sfunctionality tosession.You cannot add multiple features of the sameGObject.Typeto a session.See the main
SoupSessiondocumentation for information on what features are present in sessions by default.- Parameters:
feature- an object that implementsSoupSessionFeature
-
addFeatureByType
IffeatureTypeis 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 samefeatureTypeis not allowed.If
featureTypeis not aSessionFeaturetype, this gives each existing feature on this Session the chance to acceptfeatureTypeas a "subfeature". This can be used to add newAuthtypes, for instance.See the main
SoupSessiondocumentation 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:
trueif this Session sets "Accept-Language" header automatically, orfalseotherwise.
-
getAsyncResultMessage
Gets theMessageof theresultasynchronous operation This is useful to get theMessageof an asynchronous operation started by this Session from itsGio.AsyncReadyCallback.- Parameters:
result- theGAsyncResultpassed to your callback- Returns:
- a
SoupMessageornullifresultis not a valid this Session async operation result.
-
getFeature
Gets the feature in this Session of typefeatureType.- Parameters:
featureType- theGTypeof the feature to get- Returns:
- a
SoupSessionFeature, ornull. The feature is owned bysession.
-
getFeatureForMessage
Gets the feature in this Session of typefeatureType,provided that it is not disabled formsg.- Parameters:
featureType- theGTypeof the feature to getmsg- aSoupMessage- Returns:
- a
SoupSessionFeature. The feature is owned bysession.
-
getIdleTimeout
public int getIdleTimeout()Get the timeout in seconds for idle connection lifetime currently used bysession.- Returns:
- the timeout in seconds
-
getLocalAddress
Get theInetSocketAddressto use for the client side of connections insession.- 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 theProxyResolvercurrently used bysession.- Returns:
- a
GProxyResolverornullif 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 bysession.- Returns:
- the timeout in seconds
-
getTlsDatabase
Get theTlsDatabasecurrently used bysession.- Returns:
- a
GTlsDatabase
-
getTlsInteraction
Get theTlsInteractioncurrently used bysession.- 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- theGTypeof the class of features to check for- Returns:
trueorfalse
-
preconnectAsync
public void preconnectAsync(Message msg, int ioPriority, @Nullable Cancellable cancellable, @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
msghost, the operation finishes successfully without creating a new connection. If a new request for the givenmsghost 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- aSoupMessageioPriority- the I/O priority of the requestcancellable- aGCancellablecallback- 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- theGAsyncResultpassed to your callback- Returns:
trueif the preconnect succeeded, orfalsein case of error.- Throws:
GErrorException- seeGError
-
removeFeature
Removesfeature'sfunctionality fromsession.- Parameters:
feature- a feature that has previously been added to this Session
-
removeFeatureByType
Removes all features of typefeatureType(or any subclass offeatureType)fromsession.- Parameters:
featureType- aGType
-
send
Synchronously sendsmsgand waits for the beginning of a response.On success, a
InputStreamwill 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,cancellablecan be used to cancel the request;send(org.gnome.soup.Message, org.gnome.gio.Cancellable)will return aIOErrorEnum.CANCELLEDerror. 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
msgis 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.Possible error domains include
SessionError,Gio.IOErrorEnum, andGio.TlsErrorwhich you may want to specifically handle.- Parameters:
msg- aSoupMessagecancellable- aGCancellable- Returns:
- a
GInputStreamfor reading the response body, ornullon error. - Throws:
GErrorException- seeGError
-
sendAndRead
Synchronously sendsmsgand reads the response body.On success, a
GLib.Byteswill 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- aSoupMessagecancellable- aGCancellable- Returns:
- a
GBytes, ornullon error. - Throws:
GErrorException- seeGError
-
sendAndReadAsync
public void sendAndReadAsync(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand reads the response body.When
callbackis called, then eithermsghas 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.Byteswith the response body.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)for more details on the general semantics.- Parameters:
msg- aSoupMessageioPriority- the I/O priority of the requestcancellable- aGCancellablecallback- 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.Byteswith the response body.- Parameters:
result- theGAsyncResultpassed to your callback- Returns:
- a
GBytes, ornullon error. - Throws:
GErrorException- seeGError
-
sendAndSplice
public long sendAndSplice(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmsgand 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- aSoupMessageoutStream- aGOutputStreamflags- a set ofGOutputStreamSpliceFlagscancellable- aGCancellable- Returns:
- a
gssizecontaining the size of the data spliced, or -1 if an error occurred. - Throws:
GErrorException- seeGError- Since:
- 3.4
-
sendAndSplice
public long sendAndSplice(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, @Nullable Cancellable cancellable) throws GErrorException Synchronously sendsmsgand 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- aSoupMessageoutStream- aGOutputStreamflags- a set ofGOutputStreamSpliceFlagscancellable- aGCancellable- Returns:
- a
gssizecontaining the size of the data spliced, or -1 if an error occurred. - Throws:
GErrorException- seeGError- Since:
- 3.4
-
sendAndSpliceAsync
public void sendAndSpliceAsync(Message msg, OutputStream outStream, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand splices the response body stream intooutStream.Whencallbackis called, then eithermsghas 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- aSoupMessageoutStream- aGOutputStreamflags- a set ofGOutputStreamSpliceFlagsioPriority- the I/O priority of the requestcancellable- aGCancellablecallback- the callback to invoke- Since:
- 3.4
-
sendAndSpliceAsync
public void sendAndSpliceAsync(Message msg, OutputStream outStream, OutputStreamSpliceFlags flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand splices the response body stream intooutStream.Whencallbackis called, then eithermsghas 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- aSoupMessageoutStream- aGOutputStreamflags- a set ofGOutputStreamSpliceFlagsioPriority- the I/O priority of the requestcancellable- aGCancellablecallback- the callback to invoke- Since:
- 3.4
-
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- theGAsyncResultpassed to your callback- Returns:
- a
gssizecontaining the size of the data spliced, or -1 if an error occurred. - Throws:
GErrorException- seeGError- Since:
- 3.4
-
sendAsync
public void sendAsync(Message msg, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously sendsmsgand waits for the beginning of a response.When
callbackis called, then eithermsghas been sent, and its response headers received, or else an error has occurred. CallsendFinish(org.gnome.gio.AsyncResult)to get aInputStreamfor reading the response body.See
send(org.gnome.soup.Message, org.gnome.gio.Cancellable)for more details on the general semantics.- Parameters:
msg- aSoupMessageioPriority- the I/O priority of the requestcancellable- aGCancellablecallback- 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
InputStreamthat can be used to read the response body.- Parameters:
result- theGAsyncResultpassed to your callback- Returns:
- a
GInputStreamfor reading the response body, ornullon error. - Throws:
GErrorException- seeGError
-
setAcceptLanguage
Set the value to use for the "Accept-Language" header onMessages sent fromsession.If
acceptLanguageisnullthen no "Accept-Language" will be included in requests. SeeSession:accept-languagefor 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-autofor 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-timeoutfor more information.- Parameters:
timeout- a timeout in seconds
-
setProxyResolver
Set aProxyResolverto be used by this Session on new connections.If
proxyResolverisnullthen no proxies will be used. SeeSession:proxy-resolverfor more information.- Parameters:
proxyResolver- aGProxyResolverornull
-
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:timeoutfor more information.- Parameters:
timeout- a timeout in seconds
-
setTlsDatabase
Set aTlsDatabaseto be used by this Session on new connections.If
tlsDatabaseisnullthen certificate validation will always fail. SeeSession:tls-databasefor more information.- Parameters:
tlsDatabase- aGTlsDatabase
-
setTlsInteraction
Set aTlsInteractionto be used by this Session on new connections.If
tlsInteractionisnullthen client certificate validation will always fail.See
Session:tls-interactionfor more information.- Parameters:
tlsInteraction- aGTlsInteraction
-
setUserAgent
Set the value to use for the "User-Agent" header onMessages sent fromsession.If
userAgenthas trailing whitespace, this Session will append its own product token (eg,libsoup/3.0.0) to the end of the header for you. IfuserAgentisnullthen no "User-Agent" will be included in requests. SeeSession:user-agentfor more information.- Parameters:
userAgent- the user agent string
-
websocketConnectAsync
public void websocketConnectAsync(Message msg, @Nullable String origin, @Nullable String @Nullable [] protocols, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously creates aWebsocketConnectionto 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'sstatus 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
msgwill contain the complete response headers and body from the server's response, andwebsocketConnectFinish(org.gnome.gio.AsyncResult)will returnWebsocketError.NOT_WEBSOCKET.- Parameters:
msg-SoupMessageindicating the WebSocket server to connect toorigin- origin of the connectionprotocols- anull-terminated array of protocols supportedioPriority- the I/O priority of the requestcancellable- aGCancellablecallback- the callback to invoke
-
websocketConnectFinish
Gets theWebsocketConnectionresponse 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
WebsocketConnectionthat can be used to communicate with the server.- Parameters:
result- theGAsyncResultpassed to your callback- Returns:
- a new
SoupWebsocketConnection, ornullon 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-queuedis emitted, indicating that the session has become aware of the request.After a connection is available to send the request various
Messagesignals are emitted as the message is processed. If the message is requeued, it will emitMessage::restarted, which will then be followed by otherMessagesignals 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-unqueuedto indicate that it is done with the message.To sum up:
Session::request-queuedandSession::request-unqueuedare guaranteed to be emitted exactly once, butMessage::finished(and all of the otherMessagesignals) 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'squeue, indicating thatsessionis done with it.See
Session::request-queuedfor 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.Builderobject constructs aSessionwith the specified properties. Use the variousset...()methods to set properties, and finish construction withSession.Builder.build().- Returns:
- the builder object
-