pub struct CorsConfig {
pub origins: CorsOrigins,
pub credentials: bool,
pub max_age_secs: Option<u64>,
}Expand description
CORS policy configuration used by AppBuilder::cors.
Defaults to mirroring the request origin (permissive but not *).
Fields§
§origins: CorsOrigins§credentials: bool§max_age_secs: Option<u64>Implementations§
Source§impl CorsConfig
impl CorsConfig
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive config that mirrors the request origin (the default).
Sourcepub fn with_origins(origins: &[&str]) -> Self
pub fn with_origins(origins: &[&str]) -> Self
Create a config that allows only the specified origins.
Sourcepub fn with_custom_check(
f: impl Fn(&str) -> bool + Send + Sync + 'static,
) -> Self
pub fn with_custom_check( f: impl Fn(&str) -> bool + Send + Sync + 'static, ) -> Self
Create a config with a custom origin predicate.
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validates the CORS configuration.
Returns an error if credentials is true with Any or Mirror
origins, which would allow any origin to send credentialed requests.
Sourcepub fn into_layer(self) -> CorsLayer
pub fn into_layer(self) -> CorsLayer
Convert into a tower-http CorsLayer for use in the middleware stack.
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 Default for CorsConfig
impl Default for CorsConfig
Source§impl From<CorsYamlConfig> for CorsConfig
impl From<CorsYamlConfig> for CorsConfig
Source§fn from(yaml: CorsYamlConfig) -> Self
fn from(yaml: CorsYamlConfig) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for CorsConfig
impl !RefUnwindSafe for CorsConfig
impl Send for CorsConfig
impl Sync for CorsConfig
impl Unpin for CorsConfig
impl UnsafeUnpin 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