HTTP (harp.http)

class AlreadyHandledHttpResponse[source]

Bases: HttpResponse

__init__()[source]
class BaseHttpMessage[source]

Bases: BaseMessage

property body: bytes
property headers: MultiDictProxy
protocol: str = 'http'
class BaseMessage[source]

Bases: object

__init__(*, extensions=None)[source]
Parameters:

extensions (dict | None)

async aread()[source]
created_at: datetime
property extensions: dict
kind: str
protocol: str
class HttpError[source]

Bases: BaseHttpMessage

__init__(message, /, *, exception=None, status=500, verbose_message=None)[source]
Parameters:
property body: bytes
property headers: MultiDictProxy
kind: str = 'error'
class HttpRequest[source]

Bases: BaseHttpMessage

__init__(impl=None, *, extensions=None, **kwargs)[source]
Parameters:
async aread()[source]

Read all chunks from request. We may want to be able to read partial body later, but for now it’s all or nothing. This method does nothing if the body has already been read.

Return type:

bytes

property basic_auth: tuple[str, str] | None

Parse and returns basic auth from headers.

property body: bytes

Returns the previously read body of the request. Raises a RuntimeError if the body has not been read yet, you must await the read() asynchronous method first, which cannot be done here because properties are synchronous, so we let the user explicitely call it before.

property cookies: dict
property headers: CIMultiDict
kind: str = 'request'
property stream
class HttpRequestBridge[source]

Bases: Protocol

The HttpRequestBridge protocol defines the methods required by the HttpRequest object for it to attach to a real implementation, such as WSGI, ASGI, …

__init__(*args, **kwargs)
async aread()[source]
Return type:

bytes

get_headers()[source]
Return type:

CIMultiDict

get_method()[source]
Return type:

str

get_path()[source]
Return type:

str

get_query()[source]
Return type:

MultiDict

get_server_ipaddr()[source]
Return type:

str

get_server_port()[source]
Return type:

int

get_stream()[source]
Return type:

AsyncByteStream

class HttpRequestSerializer[source]

Bases: BaseHttpMessageSerializer

Serialize an HTTP request object into string representations for different message parts:

  • summary: the first line of the request message (e.g. “GET / HTTP/1.1”)

  • headers: the headers of the request message (e.g. “Host: localhost:4080

Connection: keep-alive …”)

  • body: the body of the request message (e.g. b’{“foo”: “bar”}’)

The main goal of this serializer is to prepare a request message for storage.

property query_string: str
property summary: str
wrapped: HttpRequest
class HttpResponse[source]

Bases: BaseHttpMessage

__init__(body, /, *, status=200, headers=None, content_type=None, extensions=None)[source]
Parameters:
async aread()[source]
property body: bytes
property content_type: str
property headers: CIMultiDict
kind: str = 'response'
property reason_phrase: str
property status: int
property stream
class HttpResponseBridge[source]

Bases: Protocol

The HttpResponseBridge protocol defines the necessary methods to actually send an HttpResponse through a real channel.

__init__(*args, **kwargs)
class JsonHttpResponse[source]

Bases: HttpResponse

__init__(body, /, *, status=200, headers=None)[source]
Parameters:
get_serializer_for(message)[source]
Parameters:

message (BaseMessage)

Return type:

MessageSerializer

Submodules