ServerMessage#
Superclasses: Object
An HTTP server request and response pair.
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 ServerMessage
combines both the request and the
response.
Methods#
- class ServerMessage
- get_http_version() HTTPVersion #
Get the HTTP version of
msg
.
- get_local_address() SocketAddress | None #
Retrieves the
SocketAddress
associated with the local end of a connection.
- get_remote_address() SocketAddress | None #
Retrieves the
SocketAddress
associated with the remote end of a connection.
- get_remote_host() str | None #
Retrieves the IP address associated with the remote end of a connection.
- get_request_body() MessageBody #
Get the request body of
msg
.
- get_request_headers() MessageHeaders #
Get the request headers of
msg
.
- get_response_body() MessageBody #
Get the response body of
msg
.
- get_response_headers() MessageHeaders #
Get the response headers of
msg
.
- get_socket() Socket | None #
Retrieves the
Socket
thatmsg
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() TlsCertificate | None #
Gets the peer’s
TlsCertificate
associated withmsg
's connection. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal.Added in version 3.2.
- get_tls_peer_certificate_errors() TlsCertificateFlags #
Gets the errors associated with validating
msg
's TLS peer certificate. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal.Added in version 3.2.
- pause() None #
Pauses I/O on
msg
.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.Added in version 3.2.
- set_http_version(version: HTTPVersion) None #
Set the HTTP version of
msg
.- Parameters:
version – a
HTTPVersion
- set_redirect(status_code: int, redirect_uri: str) None #
Sets
msg
's status_code tostatus_code
and adds a Location header pointing toredirect_uri
. Use this from aServer
when you want to redirect the client to another URI.redirect_uri
can be a relative URI, in which case it is interpreted relative tomsg
's current URI. In particular, ifredirect_uri
is just a path, it will replace the path and query ofmsg
's URI.- Parameters:
status_code – a 3xx status code
redirect_uri – the URI to redirect
msg
to
- set_response(content_type: str | None, resp_use: MemoryUse, resp_body: list[int] | None = None) None #
Convenience function to set the response body of a
ServerMessage
. Ifcontent_type
isNone
, the response body must be empty as well.- Parameters:
content_type – MIME Content-Type of the body
resp_use – a
MemoryUse
describing how to handleresp_body
resp_body – a data buffer containing the body of the message response.
Properties#
- class ServerMessage
- props.tls_peer_certificate: TlsCertificate#
The type of the None singleton.
Added in version 3.2.
- props.tls_peer_certificate_errors: TlsCertificateFlags#
The type of the None singleton.
Added in version 3.2.
Signals#
- class ServerMessage.signals
- accept_certificate(tls_peer_certificate: TlsCertificate, tls_peer_errors: TlsCertificateFlags) bool #
The type of the None singleton.
- Parameters:
tls_peer_certificate – the peer’s
TlsCertificate
tls_peer_errors – the tls errors of
tls_certificate
- got_chunk(chunk: Bytes) None #
The type of the None singleton.
- Parameters:
chunk – the just-read chunk