Headers¶
-
class
Headers
¶ A map of the key value pairs from the header portion of an HTTP request or response. The fields listed below are some common headers but the list is not exhaustive.
When each header is serialized, it is added as a property with lower_snake_case. For example, X-Forwarded-For becomes x_forwarded_for.
Typically each header’s value will be a string, however if there are multiple entries for any header, it will be a table of strings.
-
_inner
: table¶ A table containing the deserialized header key/value pairs
-
_last_key
: str¶ The last key deserialized, for multiline headers
-
static
serialize_header
(key, value)¶ Serialize a key value pair
- Parameters
key (str) –
value (str) –
- Return type
str
-
serialize
()¶ Serialize the whole set of headers separating them with a ‘\r\n’
- Return type
str
-
append_chunk
(text)¶ Append a chunk of headers to this map
- Parameters
text (str) –
-
static
from_chunk
(text)¶ Constructor for a Headers instance with the provided text
- Parameters
text (str) –
- Return type
-
static
normalize_key
(key)¶ Convert a standard header key to the normalized
lua identifer used by this collection
- Parameters
key (str) –
- Return type
str
-
append
(key, value)¶ Insert a single key value pair to the collection
- Parameters
key (str) –
value (str) –
- Return type
-
get_one
(key)¶ Get a header from the map of headers
This will first normalize the provided key. For example ‘Content-Type’ will be normalized to content_type. If more than one value is provided for that header, the last value will be provided
- Parameters
key (str) –
- Return type
str
-
get_all
(key)¶ Get a header from the map of headers as a list of strings.
In the event that a header’s key is duplicated, the value is stored internally as a list of values. This method is useful for getting that list.
This will first normalize the provided key. For example ‘Content-Type’ will be normalized to content_type.
- Parameters
key (str) –
- Return type
list[str]
-
iter
()¶ Return a lua iterator over the key/value pairs in this header map
-