:right-sidebar: True ServerMessage =================================================================== .. currentmodule:: gi.repository.Soup .. class:: ServerMessage(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` An HTTP server request and response pair. A SoupServerMessage represents an HTTP message that is being sent or received on a :obj:`~gi.repository.Soup.Server`\. :obj:`~gi.repository.Soup.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 :obj:`~gi.repository.Soup.ServerMessage` combines both the request and the response. Methods ------- .. rst-class:: interim-class .. class:: ServerMessage :no-index: .. method:: get_http_version() -> ~gi.repository.Soup.HTTPVersion Get the HTTP version of ``msg``\. .. method:: get_local_address() -> ~gi.repository.Gio.SocketAddress | None Retrieves the :obj:`~gi.repository.Gio.SocketAddress` associated with the local end of a connection. .. method:: get_method() -> str Get the HTTP method of ``msg``\. .. method:: get_reason_phrase() -> str | None Get the HTTP reason phrase of ``msg``\. .. method:: get_remote_address() -> ~gi.repository.Gio.SocketAddress | None Retrieves the :obj:`~gi.repository.Gio.SocketAddress` associated with the remote end of a connection. .. method:: get_remote_host() -> str | None Retrieves the IP address associated with the remote end of a connection. .. method:: get_request_body() -> ~gi.repository.Soup.MessageBody Get the request body of ``msg``\. .. method:: get_request_headers() -> ~gi.repository.Soup.MessageHeaders Get the request headers of ``msg``\. .. method:: get_response_body() -> ~gi.repository.Soup.MessageBody Get the response body of ``msg``\. .. method:: get_response_headers() -> ~gi.repository.Soup.MessageHeaders Get the response headers of ``msg``\. .. method:: get_socket() -> ~gi.repository.Gio.Socket | None Retrieves the :obj:`~gi.repository.Gio.Socket` that ``msg`` 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. .. method:: get_status() -> int Get the HTTP status code of ``msg``\. .. method:: get_tls_peer_certificate() -> ~gi.repository.Gio.TlsCertificate | None Gets the peer's :obj:`~gi.repository.Gio.TlsCertificate` associated with ``msg``\'s connection. Note that this is not set yet during the emission of SoupServerMessage::accept-certificate signal. .. versionadded:: 3.2 .. method:: get_tls_peer_certificate_errors() -> ~gi.repository.Gio.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. .. versionadded:: 3.2 .. method:: get_uri() -> ~gi.repository.GLib.Uri Get ``msg``\'s URI. .. method:: is_options_ping() -> bool Gets if ``msg`` represents an OPTIONS message with the path ``*``\. .. method:: 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 :obj:`~gi.repository.ServerMessage.unpause` to resume I/O. .. versionadded:: 3.2 .. method:: set_http_version(version: ~gi.repository.Soup.HTTPVersion) -> None Set the HTTP version of ``msg``\. :param version: a :obj:`~gi.repository.Soup.HTTPVersion` .. method:: set_redirect(status_code: int, redirect_uri: str) -> None Sets ``msg``\'s status_code to ``status_code`` and adds a Location header pointing to ``redirect_uri``\. Use this from a :obj:`~gi.repository.Soup.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 ``msg``\'s current URI. In particular, if ``redirect_uri`` is just a path, it will replace the path *and query* of ``msg``\'s URI. :param status_code: a 3xx status code :param redirect_uri: the URI to redirect ``msg`` to .. method:: set_response(content_type: str | None, resp_use: ~gi.repository.Soup.MemoryUse, resp_body: list[int] | None = None) -> None Convenience function to set the response body of a :obj:`~gi.repository.Soup.ServerMessage`\. If ``content_type`` is :const:`None`, the response body must be empty as well. :param content_type: MIME Content-Type of the body :param resp_use: a :obj:`~gi.repository.Soup.MemoryUse` describing how to handle ``resp_body`` :param resp_body: a data buffer containing the body of the message response. .. method:: set_status(status_code: int, reason_phrase: str | None = None) -> None Sets ``msg``\'s status code to ``status_code``\. If ``status_code`` is a known value and ``reason_phrase`` is :const:`None`, the reason_phrase will be set automatically. :param status_code: an HTTP status code :param reason_phrase: a reason phrase .. method:: unpause() -> None Resumes I/O on ``msg``\. Use this to resume after calling :obj:`~gi.repository.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. .. versionadded:: 3.2 Properties ---------- .. rst-class:: interim-class .. class:: ServerMessage :no-index: .. attribute:: props.tls_peer_certificate :type: ~gi.repository.Gio.TlsCertificate The type of the None singleton. .. versionadded:: 3.2 .. attribute:: props.tls_peer_certificate_errors :type: ~gi.repository.Gio.TlsCertificateFlags The type of the None singleton. .. versionadded:: 3.2 Signals ------- .. rst-class:: interim-class .. class:: ServerMessage.signals :no-index: .. method:: accept_certificate(tls_peer_certificate: ~gi.repository.Gio.TlsCertificate, tls_peer_errors: ~gi.repository.Gio.TlsCertificateFlags) -> bool The type of the None singleton. :param tls_peer_certificate: the peer's :obj:`~gi.repository.Gio.TlsCertificate` :param tls_peer_errors: the tls errors of ``tls_certificate`` .. method:: connected() -> None The type of the None singleton. .. method:: disconnected() -> None The type of the None singleton. .. method:: finished() -> None The type of the None singleton. .. method:: got_body() -> None The type of the None singleton. .. method:: got_chunk(chunk: ~gi.repository.GLib.Bytes) -> None The type of the None singleton. :param chunk: the just-read chunk .. method:: got_headers() -> None The type of the None singleton. .. method:: wrote_body() -> None The type of the None singleton. .. method:: wrote_body_data(chunk_size: int) -> None The type of the None singleton. :param chunk_size: the number of bytes written .. method:: wrote_chunk() -> None The type of the None singleton. .. method:: wrote_headers() -> None The type of the None singleton. .. method:: wrote_informational() -> None The type of the None singleton.