pigeon.middleware.components.cors¶
Module Contents¶
- class pigeon.middleware.components.cors.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.cors.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.cors.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.cors.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.cors.CORSComponent¶
Bases:
pigeon.middleware.components.MiddlewareComponent
Middleware component that can be used by a preprocessor or postprocessor to process requests.
- classmethod cors_origin_allowed(request: pigeon.http.HTTPRequest) bool ¶
Checks if the Origin header in the request is a valid origin.
- classmethod cors_method_allowed(request: pigeon.http.HTTPRequest) bool ¶
Returns true if the
- classmethod cors_credentials_allowed(request: pigeon.http.HTTPRequest) bool ¶
Checks if request has credentials and whether they are allowed as per CORS-policy
- classmethod cors_headers_allowed(request: pigeon.http.HTTPRequest) bool ¶
Checks if the request headers are allowed as per CORS-policy
- classmethod is_cors(request: pigeon.http.HTTPRequest) bool ¶
- classmethod allowed(request: pigeon.http.HTTPRequest) bool ¶
Checks if Origin header and Host header are valid.
- classmethod preprocess(request: pigeon.http.HTTPRequest) pigeon.http.HTTPRequest | pigeon.http.HTTPResponse ¶
- classmethod get_headers(request: pigeon.http.HTTPRequest) dict ¶
Gets server access-control response headers for request
- classmethod postprocess(response: pigeon.http.HTTPResponse, request: pigeon.http.HTTPRequest) pigeon.http.HTTPResponse ¶