pub struct Cors { /* private fields */ }Expand description
CORS middleware, see the module documentation
Implementations§
Source§impl Cors
impl Cors
Sourcepub fn new() -> Self
pub fn new() -> Self
No origin allowed yet; add some with allow_origin,
allow_origins, allow_origin_fn
or allow_any_origin
Sourcepub fn allow_origin(self, origin: impl Into<String>) -> Self
pub fn allow_origin(self, origin: impl Into<String>) -> Self
Allow one origin, written exactly as browsers send it
(https://app.example.com, no trailing slash)
pub fn allow_origins<I, S>(self, origins: I) -> Self
Sourcepub fn allow_any_origin(self) -> Self
pub fn allow_any_origin(self) -> Self
Allow every origin (Access-Control-Allow-Origin: *). Credentials are
never allowed in this mode.
Sourcepub fn allow_origin_fn<F>(self, f: F) -> Self
pub fn allow_origin_fn<F>(self, f: F) -> Self
Decide per origin, e.g. all subdomains of your own domain
Sourcepub fn allow_methods<I>(self, methods: I) -> Selfwhere
I: IntoIterator<Item = Method>,
pub fn allow_methods<I>(self, methods: I) -> Selfwhere
I: IntoIterator<Item = Method>,
Methods a cross-origin page may use (default: GET, HEAD, POST, PUT, PATCH, DELETE)
Sourcepub fn allow_headers<I, S>(self, headers: I) -> Self
pub fn allow_headers<I, S>(self, headers: I) -> Self
Request headers a cross-origin page may send. Without this call the headers named in the preflight are allowed.
Sourcepub fn expose_headers<I, S>(self, headers: I) -> Self
pub fn expose_headers<I, S>(self, headers: I) -> Self
Response headers a cross-origin page may read besides the safelisted ones
Sourcepub fn allow_credentials(self) -> Self
pub fn allow_credentials(self) -> Self
Let the page send cookies and Authorization (Access-Control-Allow-Credentials).
Ignored together with allow_any_origin.
Sourcepub fn max_age(self, max_age: Duration) -> Self
pub fn max_age(self, max_age: Duration) -> Self
How long browsers may cache a preflight answer (default 10 minutes)
Sourcepub fn allow_private_network(self) -> Self
pub fn allow_private_network(self) -> Self
Answer Private Network Access preflights, which public pages send before
reaching into a private network (Access-Control-Allow-Private-Network)