pub struct Cors { /* private fields */ }Expand description
CORS middleware
Appends CORS response headers and short-circuits OPTIONS preflight requests
with a 204 No Content response. Use Cors::permissive() for open APIs or
Cors::new() + builder methods for origin-restricted endpoints.
Implementations§
Source§impl Cors
impl Cors
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a new Cors with permissive defaults
Allows all origins (*), GET/POST/OPTIONS methods, and Content-Type/Accept headers.
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Cors builder with no allowed origins
Call allow_origins to configure allowed origins.
Sourcepub fn allow_origins<I, S>(self, origins: I) -> Self
pub fn allow_origins<I, S>(self, origins: I) -> Self
Sourcepub fn allow_methods<I, S>(self, methods: I) -> Self
pub fn allow_methods<I, S>(self, methods: I) -> Self
Set the allowed HTTP methods
Sourcepub fn allow_headers<I, S>(self, headers: I) -> Self
pub fn allow_headers<I, S>(self, headers: I) -> Self
Set the allowed request headers
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cors
impl RefUnwindSafe for Cors
impl Send for Cors
impl Sync for Cors
impl Unpin for Cors
impl UnsafeUnpin for Cors
impl UnwindSafe for Cors
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more