#[non_exhaustive]pub struct HttpServerConfig {
pub allowed_origins: Vec<String>,
}Expand description
HTTP server configuration.
§Production warning
HttpServerConfig::default() returns a configuration suitable for local development
only — it allows a single hard-coded origin (http://localhost:3000). Production
deployments must construct an explicit HttpServerConfig with the actual list of
allowed origins, or pass vec![] to deny all cross-origin requests.
Use create_pjs_router_with_config to apply a non-default configuration.
§Adding fields
This struct is marked #[non_exhaustive] so future additive fields
(e.g. allow_credentials, max_age) do not become breaking changes.
External callers cannot use the struct-init pattern; construct an instance
via HttpServerConfig::new or HttpServerConfig::default and mutate
the public fields you need.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.allowed_origins: Vec<String>List of origins allowed by the CORS layer.
§Matching semantics
Origins are matched against the request’s Origin header by case-sensitive byte
equality. This is tower_http::cors::AllowOrigin::list behavior; it is not the
case-insensitive scheme/host comparison defined by RFC 6454 §6.
In practice this matches all real browser traffic, because mainstream browsers always send lowercase scheme and host. Write your origins in lowercase.
§Special values
[](empty) — deny all cross-origin requests (fail-closed)["*"]— allow any origin (passes through totower_http::cors::Any)- Mixing
"*"with explicit origins is rejected at construction time
Implementations§
Source§impl HttpServerConfig
impl HttpServerConfig
Sourcepub fn new(allowed_origins: Vec<String>) -> Self
pub fn new(allowed_origins: Vec<String>) -> Self
Construct a configuration with an explicit list of allowed CORS origins.
Pass vec![] to deny all cross-origin requests, or vec!["*".into()]
to allow any origin. Mixing "*" with explicit origins is rejected
later when the CORS layer is built.
§Examples
use pjson_rs::infrastructure::http::HttpServerConfig;
let config = HttpServerConfig::new(vec!["https://app.example.com".into()]);
assert_eq!(config.allowed_origins.len(), 1);Trait Implementations§
Source§impl Clone for HttpServerConfig
impl Clone for HttpServerConfig
Source§fn clone(&self) -> HttpServerConfig
fn clone(&self) -> HttpServerConfig
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 HttpServerConfig
impl Debug for HttpServerConfig
Auto Trait Implementations§
impl Freeze for HttpServerConfig
impl RefUnwindSafe for HttpServerConfig
impl Send for HttpServerConfig
impl Sync for HttpServerConfig
impl Unpin for HttpServerConfig
impl UnsafeUnpin for HttpServerConfig
impl UnwindSafe for HttpServerConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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