httk.serve.http.fields

Validate HTTP field names and values against the RFC 9110 grammar.

Functions

is_field_name(value)

Report whether a value is a valid RFC 9110 field name.

is_field_value(value)

Report whether a value is an acceptable HTTP field value.

validated_headers(pairs)

Validate response header name-value pairs, rejecting duplicate names.

Module Contents

httk.serve.http.fields.is_field_name(value)[source]

Report whether a value is a valid RFC 9110 field name.

Parameters:

value (str) – The candidate field name.

Returns:

True when the value is a string of RFC 9110 tchar characters.

Return type:

bool

httk.serve.http.fields.is_field_value(value)[source]

Report whether a value is an acceptable HTTP field value.

Parameters:

value (str) – The candidate field value.

Returns:

True when the value is a non-empty string free of CR and LF.

Return type:

bool

httk.serve.http.fields.validated_headers(pairs)[source]

Validate response header name-value pairs, rejecting duplicate names.

Names must be RFC 9110 field names and values must be non-empty and free of CR and LF; header names are compared case-insensitively for uniqueness.

Parameters:

pairs (collections.abc.Iterable[tuple[str, str]]) – The header name-value pairs to validate.

Returns:

The validated pairs as an immutable tuple.

Return type:

tuple[tuple[str, str], Ellipsis]