pub struct CorsConfig {
pub allow_origins: Vec<String>,
pub allow_all_origins: bool,
pub credentials: bool,
}Expand description
Cross-Origin Resource Sharing (CORS) configuration for an HTTP server.
Controls which origins are allowed to make cross-origin requests, whether credentials are included in responses, and generates appropriate CORS headers.
Instantiated via CorsConfigBuilder to ensure the unsafe credentialed-wildcard
combination cannot be represented.
Fields§
§allow_origins: Vec<String>List of origins allowed to access the server (may contain "*").
allow_all_origins: boolWhether all origins ("*") are allowed.
credentials: boolWhether credentials (Authorization, cookies, etc.) are included in responses.
Implementations§
Source§impl CorsConfig
impl CorsConfig
Sourcepub fn preflight_response(
&self,
req_origin: Option<&str>,
) -> Response<ResponseBody>
pub fn preflight_response( &self, req_origin: Option<&str>, ) -> Response<ResponseBody>
Build a CORS preflight response (HTTP 204).
Called for OPTIONS requests. Returns appropriate CORS headers based on the
request’s Origin header and this config’s allowed origins.
Sourcepub fn apply_to_response(
&self,
resp: &mut Response<ResponseBody>,
req_origin: Option<&str>,
)
pub fn apply_to_response( &self, resp: &mut Response<ResponseBody>, req_origin: Option<&str>, )
Apply CORS headers to a response based on the request’s Origin header.
Called after a handler completes successfully. Mutates the response to add
appropriate Access-Control-* headers.
Trait Implementations§
Source§impl Clone for CorsConfig
impl Clone for CorsConfig
Source§fn clone(&self) -> CorsConfig
fn clone(&self) -> CorsConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CorsConfig
impl Debug for CorsConfig
impl Eq for CorsConfig
Source§impl PartialEq for CorsConfig
impl PartialEq for CorsConfig
impl StructuralPartialEq for CorsConfig
Auto Trait Implementations§
impl Freeze for CorsConfig
impl RefUnwindSafe for CorsConfig
impl Send for CorsConfig
impl Sync for CorsConfig
impl Unpin for CorsConfig
impl UnsafeUnpin for CorsConfig
impl UnwindSafe for CorsConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.