headers#
- class starlite.datastructures.headers.Headers#
Bases:
CIMultiDictProxy
[str
],MultiMixin
[str
]An immutable, case-insensitive for HTTP headers.
- __init__(headers: Optional[Union[Mapping[str, str], RawHeaders, MultiMapping]] = None) None #
Initialize
Headers
.- Parameters:
headers – Initial value.
- classmethod from_scope(scope: HeaderScope) Headers #
Create headers from a send-message.
- Parameters:
scope – The ASGI connection scope.
- Returns:
Headers
- Raises:
ValueError – If the message does not have a
headers
key
- to_header_list() RawHeadersList #
Raw header value.
- Returns:
A list of tuples contain the header and header-value as bytes
- class starlite.datastructures.headers.MutableScopeHeaders#
Bases:
MutableMapping
A case-insensitive, multidict-like structure that can be used to mutate headers within a
Scope
- __init__(scope: Optional[HeaderScope] = None) None #
Initialize
MutableScopeHeaders
from aHeaderScope
.- Parameters:
scope – The ASGI connection scope.
- classmethod from_message(message: Message) MutableScopeHeaders #
Construct a header from a message object.
- Parameters:
message –
Message
.- Returns:
MutableScopeHeaders.
- Raises:
ValueError – If the message does not have a
headers
key.
- add(key: str, value: str) None #
Add a header to the scope.
Notes
This method keeps duplicates.
- Parameters:
key – Header key.
value – Header value.
- Returns:
None.
- getall(key: str, default: Optional[List[str]] = None) List[str] #
Get all values of a header.
- Parameters:
key – Header key.
default – Default value to return if
name
is not found.
- Returns:
A list of strings.
- Raises:
KeyError – if no header for
name
was found anddefault
is not given.
- class starlite.datastructures.headers.Header#
Bases:
BaseModel
,ABC
An abstract type for HTTP headers.
- abstract classmethod from_header(header_value: str) Header #
Construct a header from its string representation.
- to_header(include_header_name: bool = False) str #
Get the header as string.
- Parameters:
include_header_name – should include the header name in the return value. If set to false the return value will only include the header value. if set to true the return value will be:
<header name>: <header value>
. Defaults to false.
- class starlite.datastructures.headers.CacheControlHeader#
Bases:
Header
A
cache-control
header.- classmethod from_header(header_value: str) CacheControlHeader #
Create a
CacheControlHeader
instance from the header value.- Parameters:
header_value – the header value as string
- Returns:
An instance of
CacheControlHeader
- classmethod prevent_storing() CacheControlHeader #
Create a
cache-control
header with theno-store
directive which indicates that any caches of any kind (private or shared) should not store this response.