pub struct CorsConfig { /* private fields */ }Expand description
Cross-Origin Resource Sharing (CORS) configuration.
Controls which origins, methods, and headers are allowed for cross-origin requests. By default, no origins are allowed.
§Defaults
| Setting | Default |
|---|---|
allow_any_origin | false |
allow_credentials | false |
allowed_methods | GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD |
allowed_headers | none |
expose_headers | none |
max_age | none |
§Security: Credentials and Wildcards
According to the CORS specification (Fetch Standard), when credentials
mode is enabled (allow_credentials: true), the following headers
cannot use the * wildcard value:
Access-Control-Allow-Origin(must echo the specific origin)Access-Control-Allow-Headers(must list specific headers)Access-Control-Allow-Methods(must list specific methods)Access-Control-Expose-Headers(must list specific headers)
This implementation enforces this: when allow_credentials(true) is
combined with allow_any_origin(), the response echoes back the
specific request origin instead of returning *.
§Example
ⓘ
use fastapi_core::Cors;
// Secure: specific origin with credentials
let cors = Cors::new()
.allow_origin("https://myapp.example.com")
.allow_credentials(true)
.expose_headers(["X-Request-Id"]);
// Also secure: any origin echoes back specific origin when credentials enabled
// (not recommended - prefer explicit origins for security)
let cors = Cors::new()
.allow_any_origin()
.allow_credentials(true);Trait Implementations§
Source§impl Clone for CorsConfig
impl Clone for CorsConfig
Source§fn clone(&self) -> CorsConfig
fn clone(&self) -> CorsConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CorsConfig
impl Debug for CorsConfig
Auto Trait Implementations§
impl Freeze for CorsConfig
impl RefUnwindSafe for CorsConfig
impl Send for CorsConfig
impl Sync for CorsConfig
impl Unpin for CorsConfig
impl UnwindSafe for CorsConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).