Skip to content

HTTP scope and messages

Use these mappings for the HTTP scope and the request and response events exchanged with an ASGI application.

HTTPScope

Bases: TypedDict

An HTTP request scope in Scope.

typeinstance-attribute

type: Literal['http']

asgiinstance-attribute

http_versioninstance-attribute

http_version: Literal['1.1', '2']

methodinstance-attribute

method: str

schemeinstance-attribute

scheme: str

pathinstance-attribute

path: str

raw_pathinstance-attribute

raw_path: bytes

query_stringinstance-attribute

query_string: bytes

root_pathinstance-attribute

root_path: NotRequired[str]

headersinstance-attribute

headers: ScopeHeaders

clientinstance-attribute

client: NotRequired[tuple[str, int]]

serverinstance-attribute

server: tuple[str, int | None]

stateinstance-attribute

state: NotRequired[State]

extensionsinstance-attribute

extensions: HTTPExtensions

HTTPRequest

Bases: TypedDict

An HTTP request event in ReceiveMessage.

typeinstance-attribute

type: Literal['http.request']

bodyinstance-attribute

body: NotRequired[bytes]

more_bodyinstance-attribute

more_body: NotRequired[bool]

HTTPDisconnect

Bases: TypedDict

An HTTP disconnect event in ReceiveMessage.

typeinstance-attribute

type: Literal['http.disconnect']

HTTPResponseStart

Bases: TypedDict

An HTTP response-start event in SendMessage.

typeinstance-attribute

type: Literal['http.response.start']

statusinstance-attribute

status: int

headersinstance-attribute

headers: NotRequired[Headers]

trailersinstance-attribute

trailers: NotRequired[bool]

HTTPResponseBody

Bases: TypedDict

An HTTP response-body event in SendMessage.

typeinstance-attribute

type: Literal['http.response.body']

bodyinstance-attribute

body: NotRequired[bytes]

more_bodyinstance-attribute

more_body: NotRequired[bool]

HTTPResponseTrailers

Bases: TypedDict

An HTTP response-trailers event in SendMessage.

typeinstance-attribute

type: Literal['http.response.trailers']

headersinstance-attribute

headers: Headers

more_trailersinstance-attribute

more_trailers: NotRequired[bool]

HTTPResponsePathsend

Bases: TypedDict

An HTTP path-send event in SendMessage.

typeinstance-attribute

type: Literal['http.response.pathsend']

pathinstance-attribute

path: str

HTTPResponseZeroCopySend

Bases: TypedDict

A response body segment in SendMessage, read straight from an open file.

Sent after http.response.start, as many times as wanted, and freely interleaved with http.response.body. offset defaults to the descriptor's current position and count to the rest of the file.

The descriptor stays yours: this server duplicates it and closes only the duplicate, so closing it as soon as send() returns is safe -- and, per the ASGI specification, your responsibility.

typeinstance-attribute

type: Literal['http.response.zerocopysend']

fileinstance-attribute

file: SupportsFileno

offsetinstance-attribute

offset: NotRequired[int]

countinstance-attribute

count: NotRequired[int]

more_bodyinstance-attribute

more_body: NotRequired[bool]

HTTPResponseEarlyHint

Bases: TypedDict

An RFC 8297 103 Early Hints interim response in SendMessage.

Sent after http.response.start and before the final body, as many times as wanted. Each value becomes one link field; ordering and duplicates are preserved. Offered only on HTTP/2 -- check scope["extensions"].

typeinstance-attribute

type: Literal['http.response.early_hint']
links: Iterable[bytes]