Attention

This is the documentation for HARP Proxy, actually published as an early preview. Both the software and documentation are a work in progress, and although we already use it on various production servers, they may contain inaccuracies, typographical errors, huge mistakes and empty pages. We work hard to eradicate all mistakes and implement stuff, but it is a long and tedious process. We appreciate your patience and understanding. Of course, any help will be greatly appreciated.

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__()[source]
async join()[source]
property context: dict
created_at: datetime
kind: str
protocol: str
class HttpError[source]

Bases: BaseHttpMessage

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

Bases: BaseHttpMessage

__init__(impl)[source]
Parameters:

impl (HttpRequestBridge)

async join()[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.

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

Parse and returns cookies from headers.

property headers: CIMultiDictProxy
kind: str = 'request'
property method: str

Get the HTTP method from the implementation bridge.

property path: str

Get the HTTP path from the implementation bridge.

property query: MultiDictProxy

Get the query string from the implementation bridge, as a read only proxy.

property server_ipaddr: str

Get the server IP address from the implementation bridge.

property server_port: int

Get the server port from the implementation bridge.

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)
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

async read()[source]
Return type:

bytes

async stream()[source]
Return type:

AsyncIterator[bytes]

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 summary: str
wrapped: HttpRequest
class HttpResponse[source]

Bases: BaseHttpMessage

__init__(body, /, *, status=200, headers=None, content_type=None)[source]
Parameters:
property body: bytes
property content_type: str
property headers: CIMultiDict
kind: str = 'response'
property status: int
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