pub struct CorsPolicy { /* private fields */ }Expand description
CORS policy aggregate root. Immutable after construction.
Implementations§
Source§impl CorsPolicy
impl CorsPolicy
Sourcepub fn new() -> Self
pub fn new() -> Self
Maximally permissive default: wildcard origins, no credentials, default expose headers, 3600 s preflight cache.
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Load from env. Missing variables fall back to defaults; present but unparseable values also fall back (ignored).
CORS_ALLOWED_ORIGINS— comma-separated list, or*.CORS_ALLOW_CREDENTIALS—true/1/yes/onenables.CORS_MAX_AGE— decimal seconds.
Sourcepub fn with_allowed_origins(self, origins: AllowedOrigins) -> Self
pub fn with_allowed_origins(self, origins: AllowedOrigins) -> Self
Replace the origin strategy.
Sourcepub fn with_allow_credentials(self, allow: bool) -> Self
pub fn with_allow_credentials(self, allow: bool) -> Self
Enable (or disable) credentialed requests.
Sourcepub fn with_expose_headers(self, headers: Vec<String>) -> Self
pub fn with_expose_headers(self, headers: Vec<String>) -> Self
Override the exposed-headers list.
Sourcepub fn with_max_age(self, duration: Duration) -> Self
pub fn with_max_age(self, duration: Duration) -> Self
Override the preflight cache duration.
Sourcepub fn preflight_headers(
&self,
origin: Option<&str>,
req_method: &str,
req_headers: &str,
) -> Option<Vec<(&'static str, String)>>
pub fn preflight_headers( &self, origin: Option<&str>, req_method: &str, req_headers: &str, ) -> Option<Vec<(&'static str, String)>>
Build the header set for a preflight (OPTIONS) response.
Returns None when the request origin is not permitted; the
caller MUST emit a no-CORS response (typically plain 403 or an
un-augmented 200).
req_method is the value of Access-Control-Request-Method.
req_headers is the verbatim Access-Control-Request-Headers
value (comma-separated); passing an empty string is valid and
yields an empty Access-Control-Allow-Headers.
Trait Implementations§
Source§impl Clone for CorsPolicy
impl Clone for CorsPolicy
Source§fn clone(&self) -> CorsPolicy
fn clone(&self) -> CorsPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more