API Reference
cilantro.Headers
Bases: Mapping
An immutable case-insensitive class for HTTP headers.
The headers object is read-only. For usage, keys are all considered case-insensitive, and retrieved values will all be lowercase.
The original headers data will be available as the raw
property.
Initialization
Initializes with either a list of tuples or a dictionary.
An input headers dict will be converted to a list of tuples of header keys and values in bytes without changing the case.
Internally there's a dictionary mapping every header key to a list of values. Values of the same key will be deduplicated and stored in the original order.
Equality
Any headers object with the same keys and values are considered equal.
raw
property
raw
The original headers data.
get
get(key, default=None)
Gets the first value of a header key, or a default value if not found.
list
list(key)
Lists all values of a header key in the original order.
cilantro.MutableHeaders
Bases: Headers
A mutable case-insensitive class for HTTP headers.
append
append(key, value)
Appends a value if the key exists, otherwise creates a new key.
pop
pop(key)
Removes a key and returns its values.
set
set(key, value)
Sets a value for a key, overwriting any existing values.
cilantro.response
async
response(content, *, content_type='text/plain', status=200, headers=None, charset='utf-8')
Generates a response dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
(bytes, str, dict)
|
Content of response body. |
required |
content_type |
str
|
Defaults to "text/plain". |
'text/plain'
|
status |
int
|
Defaults to 200. |
200
|
headers |
dict
|
Defaults to None. |
None
|
charset |
str
|
Defaults to "utf-8". |
'utf-8'
|
Returns:
Type | Description |
---|---|
dict[str, int | list[tuple[bytes, bytes]] | bytes]
|
A dictionary contains the status code, headers and body. |
Examples:
{
"status": 200,
"headers": [
(b"content-type", b"text/plain; charset=utf-8"),
(b"content-length", b"12")
],
"body": b"Hello world!"
}
Raises:
Type | Description |
---|---|
ValueError
|
If redirect content is not a string. |