A request a server received: its method, URL as sent, headers, and a
body that can be opened once (None: no body).
Attributes#
| Attribute | Type | Description |
|---|---|---|
source | object | |
original_url | str | |
method | str | |
stream | Stream[bytes, HttpServerError] |
Functions#
__init__#
__init__(method, url, headers, body, *, source=None, remote_address=None, protocol=None, upgrade=None, read_body=None) -> Noneread_body opens the body for reading it whole, when that
differs from streaming it.
| Parameter | Type | Description |
|---|---|---|
method | str | |
url | str | |
headers | Headers | |
body | Callable[[], Stream[bytes, object]] | None | |
source | object = None | |
remote_address | str | None = None | |
protocol | RequestProtocol | None = None | |
upgrade | Callable[[Headers], Effect[SocketService, object]] | None = None | |
read_body | Callable[[], Stream[bytes, object]] | None = None |
def __init__(
self,
method: str,
url: str,
headers: Headers,
body: Callable[[], Stream[bytes, object]] | None,
*,
source: object = None,
remote_address: str | None = None,
protocol: RequestProtocol | None = None,
upgrade: Callable[[Headers], Effect[SocketService, object]] | None = None,
read_body: Callable[[], Stream[bytes, object]] | None = None,
) -> None:
"""``read_body`` opens the body for reading it whole, when that
differs from streaming it."""
super().__init__(None, headers, remote_address, None, protocol)
self._method = method.upper()
self._original_url = url
self._body = _SharedBody(body, read_body)
self._source = source
self._upgrade = upgradeupgrade_with#
upgrade_with(*, headers=None) -> Effect[SocketService, HttpServerError]| Parameter | Type | Description |
|---|---|---|
headers | HeadersInput | None = None |
Returns Effect[SocketService, HttpServerError]
def upgrade_with(
self, *, headers: HeadersInput | None = None
) -> Effect[SocketService, HttpServerError]:
if self._upgrade is None:
return super().upgrade_with(headers=headers)
from pyfect.http.headers import from_input
from pyfect.http.origin import require_allowed_origin
upgrade = self._upgrade
upgraded = upgrade(from_input(headers)).map_error(
lambda cause: (
cause
if isinstance(cause, HttpServerError)
else request_parse_error(self, None, cause)
)
)
return require_allowed_origin(self).and_then(upgraded)modify#
modify(*, url=None, headers=None, remote_address=_UNSET, peer_address=None, protocol=None) -> ServerRequestThe request with these parts replaced (remote_address=None
removes it); its body is this request's.
| Parameter | Type | Description |
|---|---|---|
url | str | None = None | |
headers | Headers | None = None | |
remote_address | str | _Unset | None = _UNSET | |
peer_address | str | None = None | |
protocol | RequestProtocol | None = None |
Returns ServerRequest
def modify(
self,
*,
url: str | None = None,
headers: Headers | None = None,
remote_address: str | _Unset | None = _UNSET,
peer_address: str | None = None,
protocol: RequestProtocol | None = None,
) -> ServerRequest:
"""The request with these parts replaced (``remote_address=None``
removes it); its body is this request's."""
copy = self._copy()
copy._url = self.url if url is None else url
copy._headers = self._headers if headers is None else headers
copy._remote_address = (
self._remote_address if isinstance(remote_address, _Unset) else remote_address
)
copy._peer_address = self._peer_address if peer_address is None else peer_address
copy._protocol = self._protocol if protocol is None else protocol
return copyto_json#
to_json() -> dict[str, object]Returns dict[str, object]
def to_json(self) -> dict[str, object]:
from pyfect.http.url_params import redact_url
return {
"_id": "HttpServerRequest",
"method": self.method,
"url": redact_url(self.original_url),
"headers": self.headers.to_json(),
"remoteAddress": self.remote_address,
}