apifrom.security.corsο
Overviewο
Classes
Classesο
- class apifrom.security.cors.CORSMiddleware(allow_origins=None, allow_methods=None, allow_headers=None, allow_credentials=False, expose_headers=None, max_age=600)[source]ο
Middleware for handling Cross-Origin Resource Sharing (CORS).
This middleware adds appropriate CORS headers to responses and handles preflight requests with the OPTIONS method.
Initialize the CORS middleware with the specified configuration.
- param allow_origins:
A list of origins that are allowed to make requests, or β*β to allow any origin.
- param allow_methods:
A list of HTTP methods that are allowed.
- param allow_headers:
A list of HTTP headers that are allowed.
- param allow_credentials:
Whether to allow credentials (cookies, authorization headers, etc).
- param expose_headers:
A list of headers that browsers are allowed to access.
- param max_age:
The maximum time (in seconds) to cache the preflight response.
- apifrom.security.cors._create_preflight_response(request)ο
Create a response for preflight requests.
- param request:
The preflight request.
- returns:
A response with appropriate CORS headers.
- apifrom.security.cors._get_allow_origin(request)ο
Get the appropriate Access-Control-Allow-Origin header value.
- param request:
The request to process.
- returns:
The appropriate origin value.
- apifrom.security.cors.process_request(request)ο
- :async:
Process an incoming request and handle CORS preflight requests.
- param request:
The incoming request.
- returns:
A response for preflight requests, or None to continue processing.
- apifrom.security.cors.process_response(request, response)ο
Process a response by adding appropriate CORS headers.
- param request:
The request that led to this response.
- param response:
The response to process.
- returns:
The processed response with CORS headers.
- class apifrom.security.cors.Request(request=None, path_params=None, method=None, path=None, query_params=None, headers=None, body=None, client_ip=None)[source]ο
Request class for APIFromAnything.
This class wraps a Starlette request and provides methods for accessing request data in a convenient way.
- apifrom.security.cors._requestο
The underlying Starlette request.
- apifrom.security.cors.path_paramsο
Path parameters extracted from the URL.
- apifrom.security.cors.query_paramsο
Query parameters extracted from the URL.
- apifrom.security.cors.headersο
HTTP headers.
- apifrom.security.cors.methodο
HTTP method.
- apifrom.security.cors.pathο
Request path.
- apifrom.security.cors._bodyο
Cached request body.
Initialize a new Request instance.
- param request:
The underlying Starlette request.
- param path_params:
Path parameters extracted from the URL.
- param method:
The HTTP method.
- param path:
The request path.
- param query_params:
Query parameters.
- param headers:
HTTP headers.
- param body:
Request body.
- param client_ip:
Client IP address.
- class apifrom.security.cors.Response(content=None, status_code=200, headers=None, content_type='application/json')[source]ο
Response class for APIFromAnything.
This class represents an HTTP response and provides methods for setting response data, status code, and headers.
- apifrom.security.cors.contentο
The response content.
- apifrom.security.cors.status_codeο
The HTTP status code.
- apifrom.security.cors.headersο
HTTP headers.
- apifrom.security.cors.content_typeο
The content type of the response.
Initialize a new Response instance.
- param content:
The response content.
- param status_code:
The HTTP status code.
- param headers:
HTTP headers.
- param content_type:
The content type of the response.