Skip to main content

ResponseHeaders

This class provides a case-insensitive mapping for managing HTTP response headers. It ensures that header keys and values are correctly encoded to ASCII and Latin-1, respectively, while supporting MIME-encoding for non-compliant values. The class also enforces security by preventing header values from containing newline characters.

Attributes

AttributeTypeDescription
_storedict = {}Internal dictionary mapping lowercase header names to tuples of the original case-sensitive key and its encoded value.

Constructor

Signature

def ResponseHeaders(
data: Any
) - > null

Parameters

NameTypeDescription
dataAnyThe initial header data to populate the mapping with.

Methods


pop()

@classmethod
def pop(
key: string,
default: Any = None
) - > Any

Removes the specified header key and returns its value, or a default if the key is not found.

Parameters

NameTypeDescription
keystringThe case-insensitive header name to remove.
defaultAny = NoneThe value to return if the specified header key is not found in the store.

Returns

TypeDescription
AnyThe value associated with the header key, or the default value if the key does not exist.

setdefault()

@classmethod
def setdefault(
key: string,
value: Any
) - > Any

Returns the value of a header if it exists; otherwise, sets the header to the provided value and returns it.

Parameters

NameTypeDescription
keystringThe case-insensitive header name to check or set.
valueAnyThe default value to assign to the header if the key is not already present.

Returns

TypeDescription
AnyThe existing value of the header or the newly set default value.