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
| Attribute | Type | Description |
|---|---|---|
| _store | dict = {} | 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
| Name | Type | Description |
|---|---|---|
| data | Any | The 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
| Name | Type | Description |
|---|---|---|
| key | string | The case-insensitive header name to remove. |
| default | Any = None | The value to return if the specified header key is not found in the store. |
Returns
| Type | Description |
|---|---|
Any | The 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
| Name | Type | Description |
|---|---|---|
| key | string | The case-insensitive header name to check or set. |
| value | Any | The default value to assign to the header if the key is not already present. |
Returns
| Type | Description |
|---|---|
Any | The existing value of the header or the newly set default value. |