class documentation

class _NameEncoder:

View In Hierarchy

_NameEncoder converts HTTP header names to bytes and canonicalizies their capitalization.

Method __init__ Undocumented
Method encode Encode the name of a header (eg 'Content-Type') to an ISO-8859-1 bytestring if required. It will be canonicalized to Http-Header-Case.
Class Variable __slots__ Undocumented
Constant _MAX_CACHED_HEADERS Undocumented
Class Variable _caseMappings A dict that maps conventionally-capitalized header names to their canonicalized representation, for headers with unconventional capitalization.
Instance Variable _canonicalHeaderCache A dict that maps header names to their canonicalized representation.
def __init__(self):

Undocumented

def encode(self, name: str | bytes) -> bytes:

Encode the name of a header (eg 'Content-Type') to an ISO-8859-1 bytestring if required. It will be canonicalized to Http-Header-Case.

Parameters
name:str | bytesAn HTTP header name
Returns
bytesname, encoded if required, in Header-Case
Raises
InvalidHeaderNameIf the header name contains invalid characters like whitespace or NUL.
__slots__: tuple[str, ...] =

Undocumented

_MAX_CACHED_HEADERS: ClassVar[int] =

Undocumented

Value
10000
_caseMappings: ClassVar[dict[bytes, bytes]] =

A dict that maps conventionally-capitalized header names to their canonicalized representation, for headers with unconventional capitalization.

_canonicalHeaderCache: dict[bytes | str, bytes] =

A dict that maps header names to their canonicalized representation.