pigeon.middleware.components.content_negotiation¶
Module Contents¶
- class pigeon.middleware.components.content_negotiation.Manager¶
Used to manage settings and load specified middleware which is only loaded at runtime.
To override settings either the method Manager.override or the Manager.__get_attr__ method is used:
# override settings using a module or similar behaving object my_settings: types.ModuleType = ... Manager.override(my_settings) # override settings one at a time by accessing the attributes (__getattr__) Manager.my_setting = my_value
- classmethod override(new_settings: types.ModuleType | Any)¶
Overrides current settings with new settings provided.
- Parameters:
new_settings – New settings to override old ones with
- class pigeon.middleware.components.content_negotiation.HTTPRequest(method: str, path: str, headers: dict = None, get: dict = None, data=None, files=None, protocol: str = '1.1', content_type=None, **kwargs)¶
Bases:
pigeon.http.message.HTTPMessage
An HTTP message (obv either response or request)
- property is_error¶
- class pigeon.middleware.components.content_negotiation.HTTPResponse(headers: dict = None, data: str = None, status: int = 200, cookies=None, protocol: str = '1.1', content_type=None, **kwargs)¶
Bases:
pigeon.http.message.HTTPMessage
An HTTP message (obv either response or request)
- property is_error¶
- pigeon.middleware.components.content_negotiation.error(code: int, request: pigeon.http.request.HTTPRequest | None = None) pigeon.http.response.HTTPResponse | str ¶
Returns the HTTPResponse for the error code provided, request parameter optional
- class pigeon.middleware.components.content_negotiation.ContentNegotiationComponent¶
Bases:
pigeon.middleware.components.MiddlewareComponent
Implements content-negotiation as specified for HTTP/1.1 and subsequently HTTP/2.0
- classmethod postprocess(response: pigeon.http.HTTPResponse, request: pigeon.http.HTTPRequest) pigeon.http.HTTPResponse ¶
- classmethod process(request: pigeon.http.HTTPRequest, func: Callable)¶
Will change func to be to a typed view if one esists for the requested path and add automatic type conversion to func.
- classmethod negotiate_func(request) tuple[Callable | None, str | None] ¶
Returns exsiting acceptable view for request. Since untyped views are assigned the mimetype / at runtime and are often used as a fallback, if no content type is found, they will only be returned if no other matching mimetype is found.
- classmethod preprocess(request: pigeon.http.HTTPRequest) pigeon.http.HTTPRequest ¶
- classmethod parse_header(header: str) tuple ¶
Parses header value of style: <value>[;q=<quality_factor>], <value>[;q=<quality_factor>], …
- classmethod parse_accept_header(request: pigeon.http.HTTPRequest) tuple ¶
- classmethod parse_accept_encoding_header(request: pigeon.http.HTTPRequest) tuple ¶