Class ServerMessage
- All Implemented Interfaces:
Proxy
A SoupServerMessage represents an HTTP message that is being sent or
received on a Server
.
Server
will create SoupServerMessage
s 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
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theAcceptCertificateCallback
callback.static class
ServerMessage.Builder<B extends ServerMessage.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theConnectedCallback
callback.static interface
Functional interface declaration of theDisconnectedCallback
callback.static interface
Functional interface declaration of theFinishedCallback
callback.static interface
Functional interface declaration of theGotBodyCallback
callback.static interface
Functional interface declaration of theGotChunkCallback
callback.static interface
Functional interface declaration of theGotHeadersCallback
callback.static class
static interface
Functional interface declaration of theWroteBodyCallback
callback.static interface
Functional interface declaration of theWroteBodyDataCallback
callback.static interface
Functional interface declaration of theWroteChunkCallback
callback.static interface
Functional interface declaration of theWroteHeadersCallback
callback.static interface
Functional interface declaration of theWroteInformationalCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionServerMessage
(MemorySegment address) Create a ServerMessage proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ServerMessage
asParent()
Returns this instance as if it were its parent type.static ServerMessage.Builder
<? extends ServerMessage.Builder> builder()
AServerMessage.Builder
object constructs aServerMessage
with the specified properties.boolean
emitAcceptCertificate
(TlsCertificate tlsPeerCertificate, Set<TlsCertificateFlags> tlsPeerErrors) Emits the "accept-certificate" signal.void
Emits the "connected" signal.void
Emits the "disconnected" signal.void
Emits the "finished" signal.void
Emits the "got-body" signal.void
emitGotChunk
(Bytes chunk) Emits the "got-chunk" signal.void
Emits the "got-headers" signal.void
Emits the "wrote-body" signal.void
emitWroteBodyData
(int chunkSize) Emits the "wrote-body-data" signal.void
Emits the "wrote-chunk" signal.void
Emits the "wrote-headers" signal.void
Emits the "wrote-informational" signal.Get the HTTP version of this ServerMessage.Retrieves theSocketAddress
associated with the local end of a connection.Get the HTTP method of this ServerMessage.Get the HTTP reason phrase of this ServerMessage.Retrieves theSocketAddress
associated with the remote end of a connection.Retrieves the IP address associated with the remote end of a connection.Get the request body of this ServerMessage.Get the request headers of this ServerMessage.Get the response body of this ServerMessage.Get the response headers of this ServerMessage.Retrieves theSocket
that this ServerMessage is associated with.int
Get the HTTP status code of this ServerMessage.Gets the peer'sGTlsCertificate
associated with this ServerMessage's connection.Gets the errors associated with validating this ServerMessage's TLS peer certificate.static Type
getType()
Get the GType of the ServerMessage classgetUri()
Get this ServerMessage's URI.boolean
Gets if this ServerMessage represents an OPTIONS message with the path*
.Emitted during themsg
's connection TLS handshake after client TLS certificate has been received.Emitted when themsg
's socket is connected and the TLS handshake completed.Emitted when themsg
's socket 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.void
pause()
Pauses I/O on this ServerMessage.void
setHttpVersion
(HTTPVersion version) Set the HTTP version of this ServerMessage.void
setRedirect
(int statusCode, String redirectUri) Sets this ServerMessage's status_code tostatusCode
and adds a Location header pointing toredirectUri
.void
setResponse
(@Nullable String contentType, MemoryUse respUse, @org.jetbrains.annotations.Nullable byte[] respBody) Convenience function to set the response body of aSoupServerMessage
.void
Sets this ServerMessage's status code tostatusCode
."Steals" the HTTP connection associated with this ServerMessage from itsSoupServer
.void
unpause()
Resumes I/O on this ServerMessage.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, 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
-
ServerMessage
Create a ServerMessage proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
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. -
getHttpVersion
Get the HTTP version of this ServerMessage.- Returns:
- a
SoupHTTPVersion
.
-
getLocalAddress
Retrieves theSocketAddress
associated with the local end of a connection.- Returns:
- the
GSocketAddress
associated with the local end of a connection, it may benull
if you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress)
.
-
getMethod
-
getReasonPhrase
Get the HTTP reason phrase of this ServerMessage.- Returns:
- the reason phrase.
-
getRemoteAddress
Retrieves theSocketAddress
associated with the remote end of a connection.- Returns:
- the
GSocketAddress
associated with the remote end of a connection, it may benull
if you usedinvalid reference
accept_iostream
-
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
null
if you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress)
.
-
getRequestBody
Get the request body of this ServerMessage.- Returns:
- a
SoupMessageBody
.
-
getRequestHeaders
Get the request headers of this ServerMessage.- Returns:
- a
SoupMessageHeaders
with the request headers.
-
getResponseBody
Get the response body of this ServerMessage.- Returns:
- a
SoupMessageBody
.
-
getResponseHeaders
Get the response headers of this ServerMessage.- Returns:
- a
SoupMessageHeaders
with the response headers.
-
getSocket
Retrieves theSocket
that 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
GSocket
that this ServerMessage is associated with,null
if you usedServer.acceptIostream(org.gnome.gio.IOStream, org.gnome.gio.SocketAddress, org.gnome.gio.SocketAddress)
.
-
getStatus
public int getStatus()Get the HTTP status code of this ServerMessage.- Returns:
- the HTTP status code.
-
getTlsPeerCertificate
Gets the peer'sGTlsCertificate
associated with this ServerMessage's connection. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal.- Returns:
- this ServerMessage's TLS peer certificate,
or
null
if this ServerMessage's connection is not SSL.
-
getTlsPeerCertificateErrors
Gets the errors associated with validating this ServerMessage's TLS peer certificate. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal.- Returns:
- a
GTlsCertificateFlags
with this ServerMessage's TLS peer certificate errors.
-
getUri
-
isOptionsPing
public boolean isOptionsPing()Gets if this ServerMessage represents an OPTIONS message with the path*
.- Returns:
true
if is an OPTIONS ping
-
pause
public void pause()Pauses I/O on this ServerMessage.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. -
setHttpVersion
Set the HTTP version of this ServerMessage.- Parameters:
version
- aSoupHTTPVersion
-
setRedirect
Sets this ServerMessage's status_code tostatusCode
and adds a Location header pointing toredirectUri
. Use this from aServer
when you want to redirect the client to another URI.redirectUri
can be a relative URI, in which case it is interpreted relative to this ServerMessage's current URI. In particular, ifredirectUri
is just a path, it will replace the path *and query* of this ServerMessage's URI.- Parameters:
statusCode
- a 3xx status coderedirectUri
- the URI to redirect this ServerMessage to
-
setResponse
public void setResponse(@Nullable @Nullable String contentType, MemoryUse respUse, @Nullable @org.jetbrains.annotations.Nullable byte[] respBody) Convenience function to set the response body of aSoupServerMessage
. IfcontentType
isnull
, the response body must be empty as well.- Parameters:
contentType
- MIME Content-Type of the bodyrespUse
- aSoupMemoryUse
describing how to handlerespBody
respBody
- a data buffer containing the body of the message response.
-
setStatus
Sets this ServerMessage's status code tostatusCode
.If
statusCode
is a known value andreasonPhrase
isnull
, 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-informational
orServerMessage::wrote-body
signal 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
GIOStream
formerly associated with this ServerMessage (ornull
if this ServerMessage was no longer associated with a connection). No guarantees are made about what kind ofGIOStream
is returned.
-
unpause
public void unpause()Resumes I/O on this ServerMessage.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. -
onAcceptCertificate
public SignalConnection<ServerMessage.AcceptCertificateCallback> onAcceptCertificate(ServerMessage.AcceptCertificateCallback handler) Emitted during themsg
's connection TLS handshake after client TLS certificate has been received. You can returntrue
to accepttlsCertificate
despitetlsErrors
.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitAcceptCertificate
public boolean emitAcceptCertificate(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
's socket 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
's socket 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
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(org.gnome.glib.Bytes)
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.Builder
object constructs aServerMessage
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withServerMessage.Builder.build()
.
-