pub struct MiddlewareStack { /* private fields */ }Implementations§
Source§impl MiddlewareStack
impl MiddlewareStack
pub fn new() -> Self
Sourcepub fn with_csrf(self) -> Self
pub fn with_csrf(self) -> Self
Enable CSRF protection (double-submit cookie): state-changing requests
must send an X-CSRF-Token header matching the csrf_token cookie.
Sourcepub fn with_force_ssl(self) -> Self
pub fn with_force_ssl(self) -> Self
Redirect insecure requests to HTTPS (Rails force_ssl). A request is
considered secure when its X-Forwarded-Proto is https (or the URI
scheme is https); otherwise it gets a 301 to the https:// URL.
Sourcepub fn insert_before(
self,
transform: impl FnOnce(Router) -> Router + Send + 'static,
) -> Self
pub fn insert_before( self, transform: impl FnOnce(Router) -> Router + Send + 'static, ) -> Self
Insert custom middleware inside the always-on layers (closer to the
router), i.e. it runs after logging/panic-recovery on the way in. The
closure receives the router and returns it with its .layer(...) added.
Sourcepub fn insert_after(
self,
transform: impl FnOnce(Router) -> Router + Send + 'static,
) -> Self
pub fn insert_after( self, transform: impl FnOnce(Router) -> Router + Send + 'static, ) -> Self
Insert custom middleware outside the always-on layers (outermost), so it wraps the whole stack.
Sourcepub fn with_cors(self) -> Self
pub fn with_cors(self) -> Self
Enable permissive CORS (any origin/method/header). For fine-grained,
config-driven CORS use with_cors_config.
Sourcepub fn with_cors_config(self, config: CorsConfig) -> Self
pub fn with_cors_config(self, config: CorsConfig) -> Self
Enable CORS from parsed CorsConfig (spec 07 [middleware.cors]). A
config with enabled: false is ignored, keeping CORS opt-in.
Sourcepub fn with_allowed_hosts(self, hosts: Vec<String>) -> Self
pub fn with_allowed_hosts(self, hosts: Vec<String>) -> Self
Restrict requests to an allowlist of Host header values (Rails
config.hosts / ActionDispatch::HostAuthorization). An empty list
permits any host; a request whose host is not listed gets a 403.
pub fn apply(self, router: Router) -> Router
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for MiddlewareStack
impl !Sync for MiddlewareStack
impl !UnwindSafe for MiddlewareStack
impl Freeze for MiddlewareStack
impl Send for MiddlewareStack
impl Unpin for MiddlewareStack
impl UnsafeUnpin for MiddlewareStack
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<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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