Class ServerMessage
- All Implemented Interfaces:
Proxy
A SoupServerMessage represents an HTTP message that is being sent or
received on a Server.
Server will create SoupServerMessages automatically for
incoming requests, which your application will receive via handlers.
Note that libsoup's terminology here does not quite match the HTTP
specification: in RFC 2616, an "HTTP-message" is either a Request, or a
Response. In libsoup, a SoupServerMessage combines both the request and the
response.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theAcceptCertificateCallbackcallback.static classServerMessage.Builder<B extends ServerMessage.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theConnectedCallbackcallback.static interfaceFunctional interface declaration of theDisconnectedCallbackcallback.static interfaceFunctional interface declaration of theFinishedCallbackcallback.static interfaceFunctional interface declaration of theGotBodyCallbackcallback.static interfaceFunctional interface declaration of theGotChunkCallbackcallback.static interfaceFunctional interface declaration of theGotHeadersCallbackcallback.static classstatic interfaceFunctional interface declaration of theWroteBodyCallbackcallback.static interfaceFunctional interface declaration of theWroteBodyDataCallbackcallback.static interfaceFunctional interface declaration of theWroteChunkCallbackcallback.static interfaceFunctional interface declaration of theWroteHeadersCallbackcallback.static interfaceFunctional interface declaration of theWroteInformationalCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ServerMessage.ServerMessage(MemorySegment address) Create a ServerMessage proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ServerMessageasParent()Returns this instance as if it were its parent type.static ServerMessage.Builder<? extends ServerMessage.Builder> builder()AServerMessage.Builderobject constructs aServerMessagewith the specified properties.booleanemitAcceptCertificate(@Nullable TlsCertificate tlsPeerCertificate, Set<TlsCertificateFlags> tlsPeerErrors) Emits the "accept-certificate" signal.voidEmits the "connected" signal.voidEmits the "disconnected" signal.voidEmits the "finished" signal.voidEmits the "got-body" signal.voidemitGotChunk(byte @Nullable [] chunk) Emits the "got-chunk" signal.voidEmits the "got-headers" signal.voidEmits the "wrote-body" signal.voidemitWroteBodyData(int chunkSize) Emits the "wrote-body-data" signal.voidEmits the "wrote-chunk" signal.voidEmits the "wrote-headers" signal.voidEmits the "wrote-informational" signal.Get the HTTP version ofmsg.@Nullable SocketAddressRetrieves theSocketAddressassociated with the local end of a connection.Get the HTTP method ofmsg.@Nullable StringGet the HTTP reason phrase ofmsg.@Nullable SocketAddressRetrieves theSocketAddressassociated with the remote end of a connection.@Nullable StringRetrieves the IP address associated with the remote end of a connection.Get the request body ofmsg.Get the request headers ofmsg.Get the response body ofmsg.Get the response headers ofmsg.@Nullable SocketRetrieves theSocketthat this ServerMessage is associated with.intGet the HTTP status code ofmsg.@Nullable TlsCertificateGets the peer'sGTlsCertificateassociated withmsg'sconnection.Gets the errors associated with validatingmsg'sTLS peer certificate.static @Nullable TypegetType()Get the GType of the ServerMessage classgetUri()Getmsg'sURI.booleanGets if this ServerMessage represents an OPTIONS message with the path*.Emitted during themsg'sconnection TLS handshake after client TLS certificate has been received.Emitted when themsg'ssocket is connected and the TLS handshake completed.Emitted when themsg'ssocket is disconnected.onFinished(ServerMessage.FinishedCallback handler) Emitted when all HTTP processing is finished for a message.onGotBody(ServerMessage.GotBodyCallback handler) Emitted after receiving the complete request body.onGotChunk(ServerMessage.GotChunkCallback handler) Emitted after receiving a chunk of a message body.Emitted after receiving the Request-Line and request headers.Emitted immediately after writing the complete response body for a message.Emitted immediately after writing a portion of the message body to the network.Emitted immediately after writing a body chunk for a message.Emitted immediately after writing the response headers for a message.Emitted immediately after writing a 1xx (Informational) response.voidpause()Pauses I/O onmsg.voidsetHttpVersion(HTTPVersion version) Set the HTTP version ofmsg.voidsetRedirect(int statusCode, String redirectUri) Setsmsg'sstatus_code tostatusCodeand adds a Location header pointing toredirectUri.Use this from aServerwhen you want to redirect the client to another URI.voidsetResponse(@Nullable String contentType, MemoryUse respUse, @org.jspecify.annotations.Nullable byte @Nullable [] respBody) Convenience function to set the response body of aSoupServerMessage.voidSetsmsg'sstatus code tostatusCode."Steals" the HTTP connection associated with this ServerMessage from itsSoupServer.voidunpause()Resumes I/O onmsg.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, getMemoryLayout, 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
-
ServerMessage
Create a ServerMessage proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
ServerMessage
public ServerMessage()Creates a new ServerMessage.
-
-
Method Details
-
getType
-
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. -
getHttpVersion
-
getLocalAddress
Retrieves theSocketAddressassociated with the local end of a connection.- Returns:
- the
GSocketAddressassociated with the local end of a connection, it may benullif you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress).
-
getMethod
-
getReasonPhrase
Get the HTTP reason phrase ofmsg.- Returns:
- the reason phrase.
-
getRemoteAddress
Retrieves theSocketAddressassociated with the remote end of a connection.- Returns:
- the
GSocketAddressassociated with the remote end of a connection, it may benullif you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress).
-
getRemoteHost
Retrieves the IP address associated with the remote end of a connection.- Returns:
- the IP address associated with the remote
end of a connection, it may be
nullif you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress).
-
getRequestBody
-
getRequestHeaders
Get the request headers ofmsg.- Returns:
- a
SoupMessageHeaderswith the request headers.
-
getResponseBody
-
getResponseHeaders
Get the response headers ofmsg.- Returns:
- a
SoupMessageHeaderswith the response headers.
-
getSocket
Retrieves theSocketthat this ServerMessage is associated with.If you are using this method to observe when multiple requests are made on the same persistent HTTP connection (eg, as the ntlm-test test program does), you will need to pay attention to socket destruction as well (eg, by using weak references), so that you do not get fooled when the allocator reuses the memory address of a previously-destroyed socket to represent a new socket.
- Returns:
- the
GSocketthat this ServerMessage is associated with,nullif you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress).
-
getStatus
public int getStatus()Get the HTTP status code ofmsg.- Returns:
- the HTTP status code.
-
getTlsPeerCertificate
Gets the peer'sGTlsCertificateassociated withmsg'sconnection. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal.- Returns:
msg'sTLS peer certificate, ornullifmsg'sconnection is not SSL.- Since:
- 3.2
-
getTlsPeerCertificateErrors
Gets the errors associated with validatingmsg'sTLS peer certificate. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal.- Returns:
- a
GTlsCertificateFlagswithmsg'sTLS peer certificate errors. - Since:
- 3.2
-
getUri
-
isOptionsPing
public boolean isOptionsPing()Gets if this ServerMessage represents an OPTIONS message with the path*.- Returns:
trueif is an OPTIONS ping
-
pause
public void pause()Pauses I/O onmsg.This can be used when you need to return from the server handler without having the full response ready yet. Use
unpause()to resume I/O.- Since:
- 3.2
-
setHttpVersion
Set the HTTP version ofmsg.- Parameters:
version- aSoupHTTPVersion
-
setRedirect
Setsmsg'sstatus_code tostatusCodeand adds a Location header pointing toredirectUri.Use this from aServerwhen you want to redirect the client to another URI.redirectUrican be a relative URI, in which case it is interpreted relative tomsg'scurrent URI. In particular, ifredirectUriis just a path, it will replace the path *and query* ofmsg'sURI.- Parameters:
statusCode- a 3xx status coderedirectUri- the URI to redirect this ServerMessage to
-
setResponse
public void setResponse(@Nullable String contentType, MemoryUse respUse, @org.jspecify.annotations.Nullable byte @Nullable [] respBody) Convenience function to set the response body of aSoupServerMessage. IfcontentTypeisnull, the response body must be empty as well.- Parameters:
contentType- MIME Content-Type of the bodyrespUse- aSoupMemoryUsedescribing how to handlerespBodyrespBody- a data buffer containing the body of the message response.
-
setStatus
Setsmsg'sstatus code tostatusCode.If
statusCodeis a known value andreasonPhraseisnull, the reason_phrase will be set automatically.- Parameters:
statusCode- an HTTP status codereasonPhrase- a reason phrase
-
stealConnection
"Steals" the HTTP connection associated with this ServerMessage from itsSoupServer. This happens immediately, regardless of the current state of the connection; if the response to this ServerMessage has not yet finished being sent, then it will be discarded; you can steal the connection from aServerMessage::wrote-informationalorServerMessage::wrote-bodysignal handler if you need to wait for part or all of the response to be sent.Note that when calling this function from C, this ServerMessage will most likely be freed as a side effect.
- Returns:
- the
GIOStreamformerly associated with this ServerMessage (ornullif this ServerMessage was no longer associated with a connection). No guarantees are made about what kind ofGIOStreamis returned.
-
unpause
public void unpause()Resumes I/O onmsg.Use this to resume after calling
pause(), or after adding a new chunk to a chunked response. I/O won't actually resume until you return to the main loop.- Since:
- 3.2
-
onAcceptCertificate
public SignalConnection<ServerMessage.AcceptCertificateCallback> onAcceptCertificate(ServerMessage.AcceptCertificateCallback handler) Emitted during themsg'sconnection TLS handshake after client TLS certificate has been received. You can returntrueto accepttlsCertificatedespitetlsErrors.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitAcceptCertificate
public boolean emitAcceptCertificate(@Nullable TlsCertificate tlsPeerCertificate, Set<TlsCertificateFlags> tlsPeerErrors) Emits the "accept-certificate" signal. SeeonAcceptCertificate(org.gnome.soup.ServerMessage.AcceptCertificateCallback). -
onConnected
public SignalConnection<ServerMessage.ConnectedCallback> onConnected(ServerMessage.ConnectedCallback handler) Emitted when themsg'ssocket is connected and the TLS handshake completed.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitConnected
public void emitConnected()Emits the "connected" signal. SeeonConnected(org.gnome.soup.ServerMessage.ConnectedCallback). -
onDisconnected
public SignalConnection<ServerMessage.DisconnectedCallback> onDisconnected(ServerMessage.DisconnectedCallback handler) Emitted when themsg'ssocket is disconnected.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDisconnected
public void emitDisconnected()Emits the "disconnected" signal. SeeonDisconnected(org.gnome.soup.ServerMessage.DisconnectedCallback). -
onFinished
public SignalConnection<ServerMessage.FinishedCallback> onFinished(ServerMessage.FinishedCallback handler) Emitted when all HTTP processing is finished for a message. (AfterServerMessage::wrote-body).- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitFinished
public void emitFinished()Emits the "finished" signal. SeeonFinished(org.gnome.soup.ServerMessage.FinishedCallback). -
onGotBody
public SignalConnection<ServerMessage.GotBodyCallback> onGotBody(ServerMessage.GotBodyCallback handler) Emitted after receiving the complete request body.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitGotBody
public void emitGotBody()Emits the "got-body" signal. SeeonGotBody(org.gnome.soup.ServerMessage.GotBodyCallback). -
onGotChunk
public SignalConnection<ServerMessage.GotChunkCallback> onGotChunk(ServerMessage.GotChunkCallback handler) Emitted after receiving a chunk of a message body.Note that "chunk" in this context means any subpiece of the body, not necessarily the specific HTTP 1.1 chunks sent by the other side.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitGotChunk
public void emitGotChunk(byte @Nullable [] chunk) Emits the "got-chunk" signal. SeeonGotChunk(org.gnome.soup.ServerMessage.GotChunkCallback). -
onGotHeaders
public SignalConnection<ServerMessage.GotHeadersCallback> onGotHeaders(ServerMessage.GotHeadersCallback handler) Emitted after receiving the Request-Line and request headers.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitGotHeaders
public void emitGotHeaders()Emits the "got-headers" signal. SeeonGotHeaders(org.gnome.soup.ServerMessage.GotHeadersCallback). -
onWroteBody
public SignalConnection<ServerMessage.WroteBodyCallback> onWroteBody(ServerMessage.WroteBodyCallback handler) Emitted immediately after writing the complete response body for a message.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitWroteBody
public void emitWroteBody()Emits the "wrote-body" signal. SeeonWroteBody(org.gnome.soup.ServerMessage.WroteBodyCallback). -
onWroteBodyData
public SignalConnection<ServerMessage.WroteBodyDataCallback> onWroteBodyData(ServerMessage.WroteBodyDataCallback handler) Emitted immediately after writing a portion of the message body to the network.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitWroteBodyData
public void emitWroteBodyData(int chunkSize) Emits the "wrote-body-data" signal. SeeonWroteBodyData(org.gnome.soup.ServerMessage.WroteBodyDataCallback). -
onWroteChunk
public SignalConnection<ServerMessage.WroteChunkCallback> onWroteChunk(ServerMessage.WroteChunkCallback handler) Emitted immediately after writing a body chunk for a message.Note that this signal is not parallel to
ServerMessage::got-chunk; it is emitted only when a complete chunk (added withMessageBody.append(byte[])orMessageBody.appendBytes(byte[])has been written. To get more useful continuous progress information, useServerMessage::wrote-body-data.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitWroteChunk
public void emitWroteChunk()Emits the "wrote-chunk" signal. SeeonWroteChunk(org.gnome.soup.ServerMessage.WroteChunkCallback). -
onWroteHeaders
public SignalConnection<ServerMessage.WroteHeadersCallback> onWroteHeaders(ServerMessage.WroteHeadersCallback handler) Emitted immediately after writing the response headers for a message.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitWroteHeaders
public void emitWroteHeaders()Emits the "wrote-headers" signal. SeeonWroteHeaders(org.gnome.soup.ServerMessage.WroteHeadersCallback). -
onWroteInformational
public SignalConnection<ServerMessage.WroteInformationalCallback> onWroteInformational(ServerMessage.WroteInformationalCallback handler) Emitted immediately after writing a 1xx (Informational) response.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitWroteInformational
public void emitWroteInformational()Emits the "wrote-informational" signal. SeeonWroteInformational(org.gnome.soup.ServerMessage.WroteInformationalCallback). -
builder
AServerMessage.Builderobject constructs aServerMessagewith the specified properties. Use the variousset...()methods to set properties, and finish construction withServerMessage.Builder.build().- Returns:
- the builder object
-