Go to the latest version of this document.

# ``twisted`.`web`.`http_headers`.`_NameEncoder``

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: `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:`str | bytes` | An HTTP header name

Returns
`bytes` | `name`, encoded if required, in Header-Case

Raises
`InvalidHeaderName` | If 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[bytes | str, bytes]` = (source)

A `dict` that maps header names to their canonicalized representation.