http2293%python.module
fault.internet

Low-level Hypertext Transfer Protocol tools.

Provides protocol tokenization, field parsers, and protocol serialization for implementing a server or a client.

Events

BYPASS

(ev_bypass, bytes)

RLINE

For requests: (ev_rline, (method, uri, version)) For responses: (ev_rline, (version, response_code, description))

HEADERS

(ev_headers, [(bytes, bytes),...])

TRAILERS

(ev_trailers, [(bytes, bytes),...])

MESSAGE

(ev_message, None) End of message.

VIOLATION

(ev_trailers, (type, identifier, message, context))

Where type is:

'limit'

A configured limit was exceeded.

'protocol'

A protocol error occurred.

WARNING

(ev_warning, (type, identifier, message, context))

typing
import

itertools0
import

functools0
import

dataclass0
import

protocoldata0
import

ev_bypass0
data

ev_bypass = -2

ev_violation0
data

ev_violation = -1

ev_rline
data

ev_rline = 0

ev_headers
data

ev_headers = 1

ev_content
data

ev_content = 2

ev_chunk
data

ev_chunk = 3

ev_trailers
data

ev_trailers = 4

ev_message
data

ev_message = 5 # end of message

ev_warning
data

ev_warning = 6

ev_wire0
data

ev_wire = -3 # Serialization event for signalling raw transfer.

event_symbols0
data

event_symbols = {
	ev_bypass: 'bypass',
	ev_violation: 'violation',
	ev_rline: 'rline',
	ev_headers: 'headers',
	ev_content: 'content',
	ev_chunk: 'chunk',
	ev_trailers: 'trailers',
	ev_message: 'message',
	ev_warning: 'warning',
}

EOH0
data

EOH = (ev_headers, ())

EOM0
data

EOM = (ev_message, None)

@dataclass

Limits0
class

A set of numeric values used to define the limitations that should be enforced upon protocol elements when interpreting HTTP data as events.

LimitsProperties

max_line_size

Maximum length of the Request-Line or Response-Line.

max_headers

Maximum number of headers to accept.

max_trailers

Maximum number of trailers to accept.

max_header_size

len(field-name) + len(field-value)

max_header_set_size

Maximum size to scan for EOH.

max_trailer_size

len(field-name) + len(field-value)

max_chunk_line_size

Chunk size portion, not the chunk data size.

Limitsmax_line_size0
data
int

max_line_size: int = 4096

Limitsmax_headers0
data
int

max_headers: int = 1024

Limitsmax_trailers0
data
int

max_trailers: int = 32

Limitsmax_header_size0
data
int

max_header_size: int = 1024*4

Limitsmax_header_set_size0
data
int

max_header_set_size: int = 1024*8*2

Limitsmax_trailer_size0
data
int

max_trailer_size: int = 1024

Limitsmax_chunk_line_size0
data
int

max_chunk_line_size: int = 1024

Tokenization1993%
function

Tokenization()

An HTTP 1.0 and 1.1 message parser. Emits HTTP events from the given binary data. For proper response handling(HEAD), allocation must be properly constructed to retrieve the identifier and body expectation from the shared state.

The generator is configured to continue as long as the given allocation iterator produces items.

Primarily, this generator is concernced with: https://tools.ietf.org/html/rfc7230#section-3.3.3

Disassembler0
data

Disassembler = Tokenization

disassembly0
function

disassembly(**config)

Returns an already started Disassembler generator.

headers0
function

headers(headers)

Produce an iterator of bytes instances making up a segment of headers that can be joined into a buffer.

trailers0
data

trailers = headers

@functools.lru_cache(16)

chunk_size0
function

chunk_size(length)

chunk0
function

chunk(data)

Returns a tuple of (chunk-size + CRLF, chunk-data, CRLF).

Joining data into a single buffer is avoided for the express purpose of allowing the data buffer to be passed through. In cases where a shared memory segment is referenced, this can be critical for proper performance.

Currently, Serialization will concatenate these, defeating some of the purpose.

assert chunk(b"data") == (b"4\r\n", b"data", b"\r\n")

Serialization385%
function

Serialization()

Assemble HTTP events back into a sequences of bytes.

Assembler0
data

Assembler = Serialization

assembly0
function

assembly(**config)

Return a started Assembler generator.