Soup.ServerMessage¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r |
The TLS peer certificate associated with the message |
||
r |
The verification errors on the message’s TLS peer certificate |
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Emitted during the msg's connection TLS handshake after client TLS certificate has been received. |
|
Emitted when the msg's socket is connected and the TLS handshake completed. |
|
Emitted when the msg's socket is disconnected. |
|
Emitted when all HTTP processing is finished for a message. |
|
Emitted after receiving the complete request body. |
|
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. |
Fields¶
- Inherited:
Class Details¶
- class Soup.ServerMessage(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
An HTTP server request and response pair.
A
Soup.ServerMessage
represents an HTTP message that is being sent or received on a [class`Server`].[class`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
Soup.ServerMessage
combines both the request and the response.- get_http_version()¶
- Returns:
- Return type:
Get the HTTP version of self.
- get_local_address()¶
- Returns:
the
Gio.SocketAddress
associated with the local end of a connection, it may beNone
if you used [method`Server`.accept_iostream].- Return type:
Retrieves the [class`Gio`.SocketAddress] associated with the local end of a connection.
- get_reason_phrase()¶
-
Get the HTTP reason phrase of self.
- get_remote_address()¶
- Returns:
the
Gio.SocketAddress
associated with the remote end of a connection, it may beNone
if you used [class`Server`.accept_iostream].- Return type:
Retrieves the [class`Gio`.SocketAddress] associated with the remote end of a connection.
- get_remote_host()¶
- Returns:
the IP address associated with the remote end of a connection, it may be
None
if you used [method`Server`.accept_iostream].- Return type:
Retrieves the IP address associated with the remote end of a connection.
- get_request_body()¶
- Returns:
- Return type:
Get the request body of self.
- get_request_headers()¶
- Returns:
a
Soup.MessageHeaders
with the request headers.- Return type:
Get the request headers of self.
- get_response_body()¶
- Returns:
- Return type:
Get the response body of self.
- get_response_headers()¶
- Returns:
a
Soup.MessageHeaders
with the response headers.- Return type:
Get the response headers of self.
- get_socket()¶
- Returns:
the
Gio.Socket
that self is associated with,None
if you used [method`Server`.accept_iostream].- Return type:
Gio.Socket
orNone
Retrieves the [class`Gio`.Socket] that self 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.
- get_tls_peer_certificate()¶
- Returns:
self's TLS peer certificate, or
None
if self's connection is not SSL.- Return type:
Gets the peer’s
Gio.TlsCertificate
associated with self's connection. Note that this is not set yet during the emission ofSoup.ServerMessage
::accept-certificate
signal.New in version 3.2.
- get_tls_peer_certificate_errors()¶
- Returns:
a
Gio.TlsCertificateFlags
with self's TLS peer certificate errors.- Return type:
Gets the errors associated with validating self's TLS peer certificate. Note that this is not set yet during the emission of
Soup.ServerMessage
::accept-certificate
signal.New in version 3.2.
- is_options_ping()¶
-
Gets if self represents an OPTIONS message with the path
*
.
- pause()¶
Pauses I/O on self.
This can be used when you need to return from the server handler without having the full response ready yet. Use [method`ServerMessage`.unpause] to resume I/O.
New in version 3.2.
- set_http_version(version)¶
- Parameters:
version (
Soup.HTTPVersion
) – aSoup.HTTPVersion
Set the HTTP version of self.
- set_redirect(status_code, redirect_uri)¶
-
Sets self's status_code to status_code and adds a Location header pointing to redirect_uri. Use this from a [class`Server`] when you want to redirect the client to another URI.
redirect_uri can be a relative URI, in which case it is interpreted relative to self's current URI. In particular, if redirect_uri is just a path, it will replace the path *and query* of self's URI.
- set_response(content_type, resp_use, resp_body)¶
- Parameters:
resp_use (
Soup.MemoryUse
) – aSoup.MemoryUse
describing how to handle resp_bodyresp_body (
bytes
orNone
) – a data buffer containing the body of the message response.
Convenience function to set the response body of a
Soup.ServerMessage
. If content_type isNone
, the response body must be empty as well.
- set_status(status_code, reason_phrase)¶
-
Sets self's status code to status_code.
If status_code is a known value and reason_phrase is
None
, the reason_phrase will be set automatically.
- steal_connection()¶
- Returns:
the
Gio.IOStream
formerly associated with self (orNone
if self was no longer associated with a connection). No guarantees are made about what kind ofGio.IOStream
is returned.- Return type:
“Steals” the HTTP connection associated with self from its
Soup.Server
. This happens immediately, regardless of the current state of the connection; if the response to self has not yet finished being sent, then it will be discarded; you can steal the connection from a [signal`ServerMessage`:py:func:::wrote-informational<Soup.ServerMessage.signals.wrote_informational>] or [signal`ServerMessage`:py:func:::wrote-body<Soup.ServerMessage.signals.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, self will most likely be freed as a side effect.
- unpause()¶
Resumes I/O on self.
Use this to resume after calling [method`ServerMessage`.pause], or after adding a new chunk to a chunked response. I/O won’t actually resume until you return to the main loop.
New in version 3.2.
Signal Details¶
- Soup.ServerMessage.signals.accept_certificate(server_message, tls_peer_certificate, tls_peer_errors)¶
- Signal Name:
accept-certificate
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signaltls_peer_certificate (
Gio.TlsCertificate
) – the peer’sGio.TlsCertificate
tls_peer_errors (
Gio.TlsCertificateFlags
) – the tls errors of tls_certificate
- Returns:
True
to accept the TLS certificate and stop other handlers from being invoked, orFalse
to propagate the event further.- Return type:
Emitted during the msg's connection TLS handshake after client TLS certificate has been received. You can return
True
to accept tls_certificate despite tls_errors.
- Soup.ServerMessage.signals.connected(server_message)¶
- Signal Name:
connected
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted when the msg's socket is connected and the TLS handshake completed.
- Soup.ServerMessage.signals.disconnected(server_message)¶
- Signal Name:
disconnected
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted when the msg's socket is disconnected.
- Soup.ServerMessage.signals.finished(server_message)¶
- Signal Name:
finished
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted when all HTTP processing is finished for a message. (After [signal`ServerMessage`:py:func:::wrote-body<Soup.ServerMessage.signals.wrote_body>]).
- Soup.ServerMessage.signals.got_body(server_message)¶
- Signal Name:
got-body
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted after receiving the complete request body.
- Soup.ServerMessage.signals.got_chunk(server_message, chunk)¶
- Signal Name:
got-chunk
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signalchunk (
GLib.Bytes
) – the just-read chunk
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.
- Soup.ServerMessage.signals.got_headers(server_message)¶
- Signal Name:
got-headers
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted after receiving the Request-Line and request headers.
- Soup.ServerMessage.signals.wrote_body(server_message)¶
- Signal Name:
wrote-body
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted immediately after writing the complete response body for a message.
- Soup.ServerMessage.signals.wrote_body_data(server_message, chunk_size)¶
- Signal Name:
wrote-body-data
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signalchunk_size (
int
) – the number of bytes written
Emitted immediately after writing a portion of the message body to the network.
- Soup.ServerMessage.signals.wrote_chunk(server_message)¶
- Signal Name:
wrote-chunk
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted immediately after writing a body chunk for a message.
Note that this signal is not parallel to [signal`ServerMessage`:py:func:::got-chunk<Soup.ServerMessage.signals.got_chunk>]; it is emitted only when a complete chunk (added with [method`MessageBody`.append] or [method`MessageBody`.append_bytes] has been written. To get more useful continuous progress information, use [signal`ServerMessage`:py:func:::wrote-body-data<Soup.ServerMessage.signals.wrote_body_data>].
- Soup.ServerMessage.signals.wrote_headers(server_message)¶
- Signal Name:
wrote-headers
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted immediately after writing the response headers for a message.
- Soup.ServerMessage.signals.wrote_informational(server_message)¶
- Signal Name:
wrote-informational
- Flags:
- Parameters:
server_message (
Soup.ServerMessage
) – The object which received the signal
Emitted immediately after writing a 1xx (Informational) response.
Property Details¶
- Soup.ServerMessage.props.tls_peer_certificate¶
- Name:
tls-peer-certificate
- Type:
- Default Value:
- Flags:
The peer’s
Gio.TlsCertificate
associated with the messageNew in version 3.2.
- Soup.ServerMessage.props.tls_peer_certificate_errors¶
- Name:
tls-peer-certificate-errors
- Type:
- Default Value:
- Flags:
The verification errors on
Soup.ServerMessage
:tls-peer-certificate
New in version 3.2.