Skip to content

Scopes and extensions

These types in h2corn.types describe values shared by the HTTP, WebSocket, and lifespan scope contracts. Extension mappings are server metadata and should be treated as read-only; the outer scope["extensions"] mapping remains the per-scope place for an application's namespaced key.

ASGIVersionsmodule-attribute

HTTPASGIVersions

Bases: TypedDict

versioninstance-attribute

version: Literal['3.0']

spec_versioninstance-attribute

spec_version: Literal['2.5']

LifespanASGIVersions

Bases: TypedDict

versioninstance-attribute

version: Literal['3.0']

spec_versioninstance-attribute

spec_version: Literal['2.0']

HeaderPairmodule-attribute

HeaderPair = tuple[bytes, bytes]

Headersmodule-attribute

Headers = Iterable[HeaderPair]

ScopeHeadersmodule-attribute

ScopeHeaders = list[HeaderPair]

Statemodule-attribute

State = dict[str, Any]

Extensionsmodule-attribute

HTTPExtensionsmodule-attribute

HTTPExtensions = TypedDict(
    'HTTPExtensions',
    {
        'http.response.pathsend': ExtensionParameters,
        'http.response.zerocopysend': NotRequired[ExtensionParameters],
        'http.response.trailers': NotRequired[ExtensionParameters],
        'http.response.early_hint': NotRequired[ExtensionParameters],
        'tls': NotRequired[TLSExtension],
    },
)

WebSocketExtensionsmodule-attribute

WebSocketExtensions = TypedDict(
    'WebSocketExtensions',
    {
        'websocket.http.response': ExtensionParameters,
        'tls': NotRequired[TLSExtension],
    },
)

ExtensionParametersmodule-attribute

ExtensionParameters = Mapping[str, Any]

TLSExtension

Bases: TypedDict

The negotiated TLS parameters, under scope["extensions"]["tls"].

Present only on connections h2corn terminated itself; a connection arriving through a TLS-terminating proxy has no tls key at all.

client_cert_chain holds the certificates the peer presented, in PEM, leaf first — empty unless client_cert_mode asked for one. When the chain is nonempty, client_cert_name is the leaf subject as an RFC 4514 string. client_cert_error is always None: a certificate that fails verification fails the handshake and never reaches an application.

server_certinstance-attribute

server_cert: str | None

client_cert_chaininstance-attribute

client_cert_chain: tuple[str, ...]

client_cert_nameinstance-attribute

client_cert_name: str | None

client_cert_errorinstance-attribute

client_cert_error: str | None

tls_versioninstance-attribute

tls_version: int | None

cipher_suiteinstance-attribute

cipher_suite: int | None

Extension mapping fields

ASGI extension keys use dotted names and map to their parameter types.

HTTPExtensions["http.response.pathsend"]

Advertised on HTTP scopes. The application may send http.response.pathsend when the server should open the named file as the terminal response body.

HTTPExtensions["http.response.zerocopysend"]

Advertised on Unix HTTP listeners. The application may send a file descriptor or range without routing its bytes through Python; see Sending a file.

HTTPExtensions["http.response.trailers"]

Advertised when the HTTP client sent TE: trailers; the application may then send HTTP response trailers after the body.

HTTPExtensions["http.response.early_hint"]

Advertised for HTTP/2 requests. The application may send RFC 8297 103 Early Hints before the final response.

HTTPExtensions["tls"]

Present only when h2corn terminated TLS on the connection. Its value is the TLSExtension mapping; a TLS-terminating proxy does not produce this key.

WebSocketExtensions["websocket.http.response"]

Advertised on every WebSocket scope. Its value is the empty ExtensionParameters mapping for the HTTP response extension.

WebSocketExtensions["tls"]

Present only when h2corn terminated TLS on the WebSocket connection, with the same TLSExtension value and proxy boundary as HTTP.