pub struct AllowOrigin(/* private fields */);Expand description
Configuration for the Access-Control-Allow-Origin header.
Implementations§
Source§impl AllowOrigin
impl AllowOrigin
Sourcepub fn exact(origin: HeaderValue) -> Self
pub fn exact(origin: HeaderValue) -> Self
Allows a single, fixed origin.
§Panics
Panics if origin is the wildcard (*); use AllowOrigin::any for that.
Sourcepub fn list<I>(origins: I) -> Selfwhere
I: IntoIterator<Item = HeaderValue>,
pub fn list<I>(origins: I) -> Selfwhere
I: IntoIterator<Item = HeaderValue>,
Allows origins from a list. The response carries the request’s Origin verbatim if
(and only if) it appears in the list.
§Panics
Panics if origins contains the wildcard (*); use AllowOrigin::any for that.
Sourcepub fn predicate<F>(f: F) -> Self
pub fn predicate<F>(f: F) -> Self
Allows origins decided by a synchronous predicate. The predicate receives the
request’s Origin header (if any) and the request Parts,
and returns true to allow.
Sourcepub fn async_predicate<F, Fut>(f: F) -> Selfwhere
F: Fn(HeaderValue, RequestParts) -> Fut + Send + Sync + 'static,
Fut: Future<Output = bool> + Send + 'static,
pub fn async_predicate<F, Fut>(f: F) -> Selfwhere
F: Fn(HeaderValue, RequestParts) -> Fut + Send + Sync + 'static,
Fut: Future<Output = bool> + Send + 'static,
Allows origins decided by an async predicate.
Use this when the origin decision depends on data that is not already cached in
memory (for example, a database lookup per tenant). Choosing the sync
AllowOrigin::predicate path instead carries no cost.
Sourcepub fn mirror_request() -> Self
pub fn mirror_request() -> Self
Always echoes the request’s Origin header. Equivalent to
AllowOrigin::predicate returning true for every input.