pub struct CorsPolicy {
pub origins: Vec<String>,
pub methods: Vec<String>,
pub allowed_headers: Vec<String>,
pub exposed_headers: Vec<String>,
pub credentials: bool,
pub max_age: u32,
}Expand description
A cross-origin policy.
CorsPolicy::permissive is the cors: true of the JavaScript and Python
packages: every origin, every default method and header.
Fields§
§origins: Vec<String>Allowed origins; a single * allows every origin.
methods: Vec<String>Allowed methods.
allowed_headers: Vec<String>Headers a request may carry.
exposed_headers: Vec<String>Headers a browser may read from the response.
credentials: boolWhether credentials may be sent.
max_age: u32How long a preflight result may be cached, in seconds.
Implementations§
Source§impl CorsPolicy
impl CorsPolicy
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
The permissive default policy.
Sourcepub fn with_origins<I, S>(self, origins: I) -> Self
pub fn with_origins<I, S>(self, origins: I) -> Self
The same policy restricted to the given origins.
§Examples
use lino_rest_api::cors::{cors_headers, CorsPolicy};
let policy = CorsPolicy::permissive().with_origins(["https://app.example"]);
assert!(cors_headers(&policy, Some("https://other.example")).is_empty());Sourcepub fn with_credentials(self, credentials: bool) -> Self
pub fn with_credentials(self, credentials: bool) -> Self
The same policy with credentials allowed.
Sourcepub fn with_max_age(self, max_age: u32) -> Self
pub fn with_max_age(self, max_age: u32) -> Self
The same policy with another preflight cache lifetime.
Trait Implementations§
Source§impl Clone for CorsPolicy
impl Clone for CorsPolicy
Source§fn clone(&self) -> CorsPolicy
fn clone(&self) -> CorsPolicy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CorsPolicy
impl Debug for CorsPolicy
Source§impl Default for CorsPolicy
impl Default for CorsPolicy
impl Eq for CorsPolicy
Source§impl PartialEq for CorsPolicy
impl PartialEq for CorsPolicy
impl StructuralPartialEq for CorsPolicy
Auto Trait Implementations§
impl Freeze for CorsPolicy
impl RefUnwindSafe for CorsPolicy
impl Send for CorsPolicy
impl Sync for CorsPolicy
impl Unpin for CorsPolicy
impl UnsafeUnpin for CorsPolicy
impl UnwindSafe for CorsPolicy
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.