Common Models

The root hface module defines a few classes that are reused at multiple layers of hface.

For example, TLS configuration is needed by the lowest protocol layer (because TLS handled by QUIC), it used by the middle connection layer, but it can be configured at the highest server or client layer.

The events defined in the hface.events module are returned from both sans-IO HTTPProtocol.next_event() and con-IO HTTPConnection.receive_event()

Common API

class hface.ServerTLSConfig(certfile=None, keyfile=None)

Server TLS configuration.

certfile: str | None = None

File with a server certificate.

keyfile: str | None = None

File with a key for the server certificate.

clone()

Clone this instance.

Return type

ServerTLSConfig

class hface.ClientTLSConfig(insecure=False, cafile=None, capath=None, cadata=None)

Client TLS configuration.

insecure: bool = False

Allows to proceed for server without valid TLS certificates.

cafile: str | None = None

File with CA certificates to trust for server verification

capath: str | None = None

Directory with CA certificates to trust for server verification

cadata: bytes | None = None

Blob with CA certificates to trust for server verification

clone()

Clone this instance.

Return type

ClientTLSConfig

class hface.HTTPErrorCodes(protocol_error, internal_error, connect_error)

Provides commonly used error codes for a version of the HTTP protocol.

Each HTTP version uses different error codes, so we provide a few error codes for common use cases.

class hface.AddressType

Alias of Tuple[str, int]

class hface.DatagramType

Alias of Tuple[bytes, AddressType]

class hface.HeaderType

Alias of Tuple[bytes, bytes]

class hface.HeadersType

Alias of Sequence[HeaderType]

Events API

class hface.events.Event

Base class for HTTP events.

This is an abstract base class that should not be initialized.

class hface.events.ConnectionTerminated

Connection was terminated.

Extends Event.

error_code: int = 0

Reason for closing the connection.

message: str | None = None

Optional message with more information

class hface.events.GoawayReceived

GOAWAY frame was received

Extends Event.

last_stream_id: int

Highest stream ID that could be processed.

error_code: int = 0

Reason for closing the connection.

class hface.events.StreamEvent

Event on one HTTP stream.

This is an abstract base class that should not be used directly.

Extends Event.

stream_id: int

Stream ID

class hface.events.HeadersReceived

A frame with HTTP headers was received.

Extends StreamEvent.

stream_id: int

Stream ID

headers: Sequence[Tuple[bytes, bytes]]

The received HTTP headers

end_stream: bool = False

Signals that data will not be sent by the peer over the stream.

class hface.events.DataReceived

A frame with HTTP data was received.

Extends StreamEvent.

stream_id: int

Stream ID

data: bytes

The received data.

end_stream: bool = False

Signals that no more data will be sent by the peer over the stream.

class hface.events.StreamReset

One stream of an HTTP connection was reset.

When a stream is reset, it must no longer be used, but the parent connection and other streams are unaffected.

This is an abstract base class that should not be used directly. More specific subclasses (StreamResetSent or StreamResetReceived) should be emitted.

Extends StreamEvent.

stream_id: int

Stream ID

error_code: int = 0

Reason for closing the stream.

class hface.events.StreamResetReceived

One stream of an HTTP connection was reset by the peer.

This probably means that we did something that the peer does not like.

Extends StreamReset.

stream_id: int

Stream ID

error_code: int = 0

Reason for closing the stream.

class hface.events.StreamResetSent

One stream of an HTTP connection was reset by us.

This can be explicitly requested by a user, or a protocol implementation can send the reset when a peer misbehaves.

Extends StreamReset.

stream_id: int

Stream ID

error_code: int = 0

Reason for closing the stream.