class documentation

class _NameEncoder: (source)

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): (source)

Undocumented

def encode(self, name: Union[str, bytes]) -> bytes: (source)

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:Union[str, bytes]An 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, ...] = (source)

Undocumented

_MAX_CACHED_HEADERS: ClassVar[int] = (source)

Undocumented

Value
10000
_caseMappings: ClassVar[Dict[bytes, bytes]] = (source)

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

_canonicalHeaderCache: Dict[Union[bytes, str], bytes] = (source)

A dict that maps header names to their canonicalized representation.