pub enum Cors {
Disabled,
Origins(Vec<String>),
Any,
}Expand description
Cross-origin policy for router_with.
Off by default, and deliberately so. Turning this on makes every endpoint readable by any page on the internet that a browser will load — including the ones that still leak gated content — so it stays a decision a host makes explicitly rather than one it inherits.
Variants§
Disabled
No CORS headers at all. A browser SPA must be same-origin, or sit behind a reverse proxy that makes it so.
Origins(Vec<String>)
Allow exactly these origins. Credentials are permitted, so the member session cookie can travel — which is why a wildcard is not offered here.
Any
Reflect any origin. Development only: combined with credentials this would let any site read a signed-in member’s content, so credentials are not enabled in this mode.
Implementations§
Source§impl Cors
impl Cors
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Read an allowlist from RCMS_API_CORS_ORIGINS — comma-separated,
or the literal * for Cors::Any. Absent or empty is
Cors::Disabled, so an unset environment changes nothing.
Sourcepub fn parse(raw: Option<&str>) -> Self
pub fn parse(raw: Option<&str>) -> Self
The parsing half of Self::from_env, split out so it can be tested.
Process environment is global mutable state, and Rust runs tests in parallel threads — a test that sets a variable races every other test that reads one. Keeping the logic pure sidesteps that instead of papering over it with a mutex.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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