Built-in middleware: CORS.
Provides a standards-compliant CORS middleware that handles preflight requests and adds appropriate headers to all responses.
middleware.builtin
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
CORS middleware configuration.
All fields have secure defaults (nothing is allowed). Override what you need::
CORSConfig(
allow_origins=["https://example.com"],
allow_methods=["GET", "POST"],
)
Standards-compliant CORS middleware.
Handles:
- Preflight
OPTIONSrequests (returns 204 with CORS headers) - Simple and actual requests (adds CORS headers to response)
- Credential support (…
CORSConfig
class
CORS middleware configuration.
All fields have secure defaults (nothing is allowed). Override what you need::
CORSConfig(
allow_origins=["https://example.com"],
allow_methods=["GET", "POST"],
)
CORSMiddleware
class
Standards-compliant CORS middleware.
Handles:
- Preflight
OPTIONSrequests (returns 204 with CORS headers) - Simple and actual requests (adds CORS headers to response)
- Credential support (
Access-Control-Allow-Credentials) - Wildcard origins (
"*") when credentials are disabled
Usage::
app.add_middleware(CORSMiddleware(CORSConfig(
allow_origins=["https://example.com"],
allow_methods=["GET", "POST", "PUT"],
allow_headers=["Content-Type", "Authorization"],
)))
View source · /home/runner/work/chirp/chirp/site/../src/chirp/middleware/builtin.py:1