pub struct RewriteLayer { /* private fields */ }Expand description
Implementations§
Source§impl RewriteLayer
impl RewriteLayer
pub fn new() -> RewriteLayer
Sourcepub fn request_header_set(self, name: &str, value: &str) -> RewriteLayer
pub fn request_header_set(self, name: &str, value: &str) -> RewriteLayer
Add or replace a request header (case-insensitive name match).
Sourcepub fn request_header_remove(self, name: &str) -> RewriteLayer
pub fn request_header_remove(self, name: &str) -> RewriteLayer
Remove a request header (case-insensitive).
Sourcepub fn request_uri_set(self, uri: &str) -> RewriteLayer
pub fn request_uri_set(self, uri: &str) -> RewriteLayer
Replace the entire request URI.
Sourcepub fn request_uri_strip_prefix(self, prefix: &str) -> RewriteLayer
pub fn request_uri_strip_prefix(self, prefix: &str) -> RewriteLayer
Strip a path prefix from the request URI. No-op if the prefix is absent.
Normalizes to "/" if stripping leaves an empty path.
Sourcepub fn request_uri_add_prefix(self, prefix: &str) -> RewriteLayer
pub fn request_uri_add_prefix(self, prefix: &str) -> RewriteLayer
Prepend a prefix to the request URI.
Sourcepub fn request_uri_regex_rewrite(
self,
pattern: &str,
replacement: &str,
) -> Result<RewriteLayer, Error>
Available on crate feature rewrite-regex only.
pub fn request_uri_regex_rewrite( self, pattern: &str, replacement: &str, ) -> Result<RewriteLayer, Error>
rewrite-regex only.Rewrite the request URI by regex, nginx rewrite-directive style.
If pattern matches anywhere in the URI, the entire URI is
replaced by replacement with capture-group references expanded —
$1, $2, … for numbered groups, ${name} for named groups
((?P<name>...)), or $0/${0} for the whole match. If pattern
does not match, the URI is left unchanged.
Returns Err if pattern is not a valid regex. Requires the
rewrite-regex feature.
Sourcepub fn response_header_set(self, name: &str, value: &str) -> RewriteLayer
pub fn response_header_set(self, name: &str, value: &str) -> RewriteLayer
Add or replace a response header (case-insensitive name match).
Sourcepub fn response_header_remove(self, name: &str) -> RewriteLayer
pub fn response_header_remove(self, name: &str) -> RewriteLayer
Remove a response header (case-insensitive).
Sourcepub fn response_status(self, code: i16, reason: &str) -> RewriteLayer
pub fn response_status(self, code: i16, reason: &str) -> RewriteLayer
Override the response status code and reason phrase.
Sourcepub fn response_body_replace(self, from: &str, to: &str) -> RewriteLayer
pub fn response_body_replace(self, from: &str, to: &str) -> RewriteLayer
Byte-level find-and-replace across all response body content ranges.
Trait Implementations§
Source§impl Middleware for RewriteLayer
impl Middleware for RewriteLayer
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when this layer’s own work for request never blocks (in-memory
state, atomics, short mutexes) — see Application::runs_inline. A
WithMiddleware stack runs inline only if every layer and the inner
application agree. Default false.Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer never reads request.body, so the inner
application may receive it as a stream (Application::streams_body).
A layer that inspects the body (CSRF tokens in a form, request
signatures, rewriting) must keep the default false: it would see an
empty body.Source§fn answers_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn answers_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer answers request itself — it doesn’t call
next — and reads its body as a stream (a proxy forwarding it as it
arrives). The body is then streamed whatever the layers after it and
the application would say. Requires accepts_streamed_body. Since
18.3.0.Source§fn layer_name(&self) -> &'static str
fn layer_name(&self) -> &'static str
Application::middleware_names): by default the type’s name
without its module path or generic parameters (CacheLayer). Since
18.28.0.Auto Trait Implementations§
impl Freeze for RewriteLayer
impl RefUnwindSafe for RewriteLayer
impl Send for RewriteLayer
impl Sync for RewriteLayer
impl Unpin for RewriteLayer
impl UnsafeUnpin for RewriteLayer
impl UnwindSafe for RewriteLayer
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
map-response-body only.Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
trace only.Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
trace only.