pub struct AllowList { /* private fields */ }
Expand description
A CORS allow list which allowes hosts, methods, and headers from a associated path.
This is a builder-like struct.
Use the add_*
methods to add allowed origins, methods, and headers.
Multiple allow lists can be added to a Cors
instance.
See the example at Cors
.
Use RuleSet::add
to add a rule.
Implementations§
source§impl AllowList
impl AllowList
sourcepub fn new(cache_for: Duration) -> Self
pub fn new(cache_for: Duration) -> Self
Creates a empty CORS allow list with the client cache duration of cache_for
.
sourcepub fn add_origin(self, allowed_origin: impl AsRef<str>) -> Self
pub fn add_origin(self, allowed_origin: impl AsRef<str>) -> Self
Allows CORS request from allowed_origin
.
Note that the scheme (https
/ http
) is sensitive.
Use Self::add_origin_uri
for a Uri
input.
§Panics
Panics if allowed_origin
is not a valid Uri
or if it doesn’t contain a host AND a scheme.
sourcepub fn add_origin_uri(self, allowed_origin: Uri) -> Self
pub fn add_origin_uri(self, allowed_origin: Uri) -> Self
Allows CORS request from allowed_origin
.
Note that the scheme (https
/ http
) is sensitive.
§Panics
Panics if allowed_origin
doesn’t contain a host AND a scheme.
sourcepub fn allow_all_origins(self) -> Self
pub fn allow_all_origins(self) -> Self
Enables the flag to allow all origins to use the set methods and headers in CORS requests.
sourcepub fn add_method(self, allowed_method: Method) -> Self
pub fn add_method(self, allowed_method: Method) -> Self
Allows the listed origin(s) (added via Self::add_origin
)
to request using allowed_method
.
sourcepub fn allow_all_methods(self) -> Self
pub fn allow_all_methods(self) -> Self
Allows all methods.
sourcepub fn add_header(self, allowed_header: HeaderName) -> Self
pub fn add_header(self, allowed_header: HeaderName) -> Self
Allows the listed origin(s) (added via Self::add_origin
)
to send the allowed_header
in the request.
sourcepub fn check(
&self,
origin: &Uri,
) -> Option<(MethodAllowList<'_>, &[HeaderName], Duration)>
pub fn check( &self, origin: &Uri, ) -> Option<(MethodAllowList<'_>, &[HeaderName], Duration)>
Checks if the origin
is allowed according to the allow list.
Returns Some
if origin
is allowed, with the Method
s and HeaderName
s
allowed, with a cache max-age of Duration
.
Returns None
if origin
isn’t allowed.