pub type Cors = RuleSet<AllowList>;Expand description
A CORS ruleset for Kvarn.
Use Extensions::with_cors to allow selected CORS requests.
By default, Kvarn uses a empty RuleSet; all CORS requests are rejected.
§Examples
// Allow `https://icelk.dev` and `https://kvarn.org` to access all images.
// Also allow all requests from `http://example.org` access to the api.
let cors =
    Cors::empty()
        .add(
            "/images/*",
            CorsAllowList::new(Duration::from_secs(60*60*24*365))
                .add_origin("https://icelk.dev")
                .add_origin("https://kvarn.org")
            )
        .add(
            "/api/*",
            CorsAllowList::default()
                .add_origin("http://example.org")
                .add_method(Method::PUT)
                .add_method(Method::POST)
        );Aliased Type§
struct Cors { /* private fields */ }Implementations§
source§impl Cors
 
impl Cors
sourcepub fn check_origin(
    &self,
    origin: &Uri,
    uri_path: &str,
) -> Option<(MethodAllowList<'_>, &[HeaderName], Duration)>
 
pub fn check_origin( &self, origin: &Uri, uri_path: &str, ) -> Option<(MethodAllowList<'_>, &[HeaderName], Duration)>
Check if the (cross-origin) request’s origin Uri is allowed by the CORS rules.
See CorsAllowList::check for info about the return types.