Source: https://h2corn.monicz.dev/api/scopes/

# Scopes and extensions

These 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.

## ASGIVersions`module-attribute`

```python
ASGIVersions = HTTPASGIVersions | LifespanASGIVersions
```

## HTTPASGIVersions

Bases: `TypedDict`

### version`instance-attribute`

```python
version: Literal['3.0']
```

### spec\_version`instance-attribute`

```python
spec_version: Literal['2.5']
```

## LifespanASGIVersions

Bases: `TypedDict`

### version`instance-attribute`

```python
version: Literal['3.0']
```

### spec\_version`instance-attribute`

```python
spec_version: Literal['2.0']
```

## Headers`module-attribute`

```python
Headers = Iterable[HeaderPair]
```

## ScopeHeaders`module-attribute`

```python
ScopeHeaders = list[HeaderPair]
```

## State`module-attribute`

```python
State = dict[str, Any]
```

## Extensions`module-attribute`

```python
Extensions = HTTPExtensions | WebSocketExtensions
```

## HTTPExtensions`module-attribute`

```python
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]})
```

## WebSocketExtensions`module-attribute`

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

## ExtensionParameters`module-attribute`

```python
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 `cert_reqs` 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\_cert`instance-attribute`

```python
server_cert: str | None
```

### client\_cert\_chain`instance-attribute`

```python
client_cert_chain: tuple[str, ...]
```

### client\_cert\_name`instance-attribute`

```python
client_cert_name: str | None
```

### client\_cert\_error`instance-attribute`

```python
client_cert_error: str | None
```

### tls\_version`instance-attribute`

```python
tls_version: int | None
```

### cipher\_suite`instance-attribute`

```python
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](https://h2corn.monicz.dev/asgi/#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.
