Trait tower_http::ServiceBuilderExt
source · pub trait ServiceBuilderExt<L>: Sealed<L> + Sized {
Show 25 methods
// Required methods
fn propagate_header(
self,
header: HeaderName
) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>;
fn add_extension<T>(
self,
value: T
) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>;
fn map_request_body<F>(
self,
f: F
) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>;
fn map_response_body<F>(
self,
f: F
) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>;
fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>;
fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>;
fn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<HttpMakeClassifier>, L>>;
fn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<GrpcMakeClassifier>, L>>;
fn follow_redirects(
self
) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>;
fn sensitive_headers<I>(
self,
headers: I
) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>
where I: IntoIterator<Item = HeaderName>;
fn sensitive_request_headers(
self,
headers: Arc<[HeaderName]>
) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>;
fn sensitive_response_headers(
self,
headers: Arc<[HeaderName]>
) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>;
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>;
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>;
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>;
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>;
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>;
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>;
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>
where M: MakeRequestId;
fn propagate_request_id(
self,
header_name: HeaderName
) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>;
fn catch_panic(
self
) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>;
fn request_body_limit(
self,
limit: usize
) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>;
fn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>;
// Provided methods
fn set_x_request_id<M>(
self,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>
where M: MakeRequestId { ... }
fn propagate_x_request_id(
self
) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>> { ... }
}
util
only.Expand description
Extension trait that adds methods to tower::ServiceBuilder
for adding middleware from
tower-http.
§Example
use http::{Request, Response, header::HeaderName};
use bytes::Bytes;
use http_body_util::Full;
use std::{time::Duration, convert::Infallible};
use tower::{ServiceBuilder, ServiceExt, Service};
use tower_http::ServiceBuilderExt;
async fn handle(request: Request<Full<Bytes>>) -> Result<Response<Full<Bytes>>, Infallible> {
Ok(Response::new(Full::default()))
}
let service = ServiceBuilder::new()
// Methods from tower
.timeout(Duration::from_secs(30))
// Methods from tower-http
.trace_for_http()
.propagate_header(HeaderName::from_static("x-request-id"))
.service_fn(handle);
Required Methods§
sourcefn propagate_header(
self,
header: HeaderName
) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>
fn propagate_header( self, header: HeaderName ) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>
propagate-header
only.Propagate a header from the request to the response.
See tower_http::propagate_header
for more details.
sourcefn add_extension<T>(
self,
value: T
) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>
fn add_extension<T>( self, value: T ) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>
add-extension
only.Add some shareable value to request extensions.
See tower_http::add_extension
for more details.
sourcefn map_request_body<F>(
self,
f: F
) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>
fn map_request_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>
map-request-body
only.Apply a transformation to the request body.
See tower_http::map_request_body
for more details.
sourcefn map_response_body<F>(
self,
f: F
) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>
fn map_response_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>
map-response-body
only.Apply a transformation to the response body.
See tower_http::map_response_body
for more details.
sourcefn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
compression-br
or compression-deflate
or compression-gzip
or compression-zstd
only.Compresses response bodies.
See tower_http::compression
for more details.
sourcefn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
decompression-br
or decompression-deflate
or decompression-gzip
or decompression-zstd
only.Decompress response bodies.
See tower_http::decompression
for more details.
sourcefn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<HttpMakeClassifier>, L>>
fn trace_for_http( self ) -> ServiceBuilder<Stack<TraceLayer<HttpMakeClassifier>, L>>
trace
only.High level tracing that classifies responses using HTTP status codes.
This method does not support customizing the output, to do that use TraceLayer
instead.
See tower_http::trace
for more details.
sourcefn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<GrpcMakeClassifier>, L>>
fn trace_for_grpc( self ) -> ServiceBuilder<Stack<TraceLayer<GrpcMakeClassifier>, L>>
trace
only.High level tracing that classifies responses using gRPC headers.
This method does not support customizing the output, to do that use TraceLayer
instead.
See tower_http::trace
for more details.
sourcefn follow_redirects(
self
) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>
fn follow_redirects( self ) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>
follow-redirect
only.Follow redirect resposes using the Standard
policy.
See tower_http::follow_redirect
for more details.
sourcefn sensitive_headers<I>(
self,
headers: I
) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>where
I: IntoIterator<Item = HeaderName>,
fn sensitive_headers<I>(
self,
headers: I
) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>where
I: IntoIterator<Item = HeaderName>,
sensitive-headers
only.Mark headers as sensitive on both requests and responses.
See tower_http::sensitive_headers
for more details.
sourcefn sensitive_request_headers(
self,
headers: Arc<[HeaderName]>
) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>
fn sensitive_request_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>
sensitive-headers
only.Mark headers as sensitive on both requests.
See tower_http::sensitive_headers
for more details.
sourcefn sensitive_response_headers(
self,
headers: Arc<[HeaderName]>
) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>
fn sensitive_response_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>
sensitive-headers
only.Mark headers as sensitive on both responses.
See tower_http::sensitive_headers
for more details.
sourcefn override_request_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
fn override_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
set-header
only.Insert a header into the request.
If a previous value exists for the same header, it is removed and replaced with the new header value.
See tower_http::set_header
for more details.
sourcefn append_request_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
fn append_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
set-header
only.Append a header into the request.
If previous values exist, the header will have multiple values.
See tower_http::set_header
for more details.
sourcefn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
fn insert_request_header_if_not_present<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
set-header
only.Insert a header into the request, if the header is not already present.
See tower_http::set_header
for more details.
sourcefn override_response_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
fn override_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
set-header
only.Insert a header into the response.
If a previous value exists for the same header, it is removed and replaced with the new header value.
See tower_http::set_header
for more details.
sourcefn append_response_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
fn append_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
set-header
only.Append a header into the response.
If previous values exist, the header will have multiple values.
See tower_http::set_header
for more details.
sourcefn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
fn insert_response_header_if_not_present<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
set-header
only.Insert a header into the response, if the header is not already present.
See tower_http::set_header
for more details.
sourcefn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>where
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>where
M: MakeRequestId,
request-id
only.Add request id header and extension.
See tower_http::request_id
for more details.
sourcefn propagate_request_id(
self,
header_name: HeaderName
) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>
fn propagate_request_id( self, header_name: HeaderName ) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>
request-id
only.Propgate request ids from requests to responses.
See tower_http::request_id
for more details.
sourcefn catch_panic(
self
) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>
fn catch_panic( self ) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>
catch-panic
only.Catch panics and convert them into 500 Internal Server
responses.
See tower_http::catch_panic
for more details.
sourcefn request_body_limit(
self,
limit: usize
) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>
fn request_body_limit( self, limit: usize ) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>
limit
only.Intercept requests with over-sized payloads and convert them into
413 Payload Too Large
responses.
See tower_http::limit
for more details.
sourcefn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>
fn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>
normalize-path
only.Remove trailing slashes from paths.
See tower_http::normalize_path
for more details.
Provided Methods§
sourcefn set_x_request_id<M>(
self,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>where
M: MakeRequestId,
fn set_x_request_id<M>(
self,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>where
M: MakeRequestId,
request-id
only.Add request id header and extension, using x-request-id
as the header name.
See tower_http::request_id
for more details.
sourcefn propagate_x_request_id(
self
) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>
fn propagate_x_request_id( self ) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>
request-id
only.Propgate request ids from requests to responses, using x-request-id
as the header name.
See tower_http::request_id
for more details.
Object Safety§
Implementations on Foreign Types§
source§impl<L> ServiceBuilderExt<L> for ServiceBuilder<L>
impl<L> ServiceBuilderExt<L> for ServiceBuilder<L>
source§fn propagate_header(
self,
header: HeaderName
) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>
fn propagate_header( self, header: HeaderName ) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>
propagate-header
only.source§fn add_extension<T>(
self,
value: T
) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>
fn add_extension<T>( self, value: T ) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>
add-extension
only.source§fn map_request_body<F>(
self,
f: F
) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>
fn map_request_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>
map-request-body
only.source§fn map_response_body<F>(
self,
f: F
) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>
fn map_response_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>
map-response-body
only.source§fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
compression-br
or compression-deflate
or compression-gzip
or compression-zstd
only.source§fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
decompression-br
or decompression-deflate
or decompression-gzip
or decompression-zstd
only.source§fn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<HttpMakeClassifier>, L>>
fn trace_for_http( self ) -> ServiceBuilder<Stack<TraceLayer<HttpMakeClassifier>, L>>
trace
only.source§fn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<GrpcMakeClassifier>, L>>
fn trace_for_grpc( self ) -> ServiceBuilder<Stack<TraceLayer<GrpcMakeClassifier>, L>>
trace
only.source§fn follow_redirects(
self
) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>
fn follow_redirects( self ) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>
follow-redirect
only.source§fn sensitive_headers<I>(
self,
headers: I
) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>where
I: IntoIterator<Item = HeaderName>,
fn sensitive_headers<I>(
self,
headers: I
) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>where
I: IntoIterator<Item = HeaderName>,
sensitive-headers
only.source§fn sensitive_request_headers(
self,
headers: Arc<[HeaderName]>
) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>
fn sensitive_request_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>
sensitive-headers
only.source§fn sensitive_response_headers(
self,
headers: Arc<[HeaderName]>
) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>
fn sensitive_response_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>
sensitive-headers
only.source§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
fn override_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
set-header
only.source§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
fn append_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
set-header
only.source§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
fn insert_request_header_if_not_present<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>
set-header
only.source§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
fn override_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
set-header
only.source§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
fn append_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
set-header
only.source§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M
) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
fn insert_response_header_if_not_present<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>
set-header
only.source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>where
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M
) -> ServiceBuilder<Stack<SetRequestIdLayer<M>, L>>where
M: MakeRequestId,
request-id
only.source§fn propagate_request_id(
self,
header_name: HeaderName
) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>
fn propagate_request_id( self, header_name: HeaderName ) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>
request-id
only.source§fn catch_panic(
self
) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>
fn catch_panic( self ) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>
catch-panic
only.source§fn request_body_limit(
self,
limit: usize
) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>
fn request_body_limit( self, limit: usize ) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>
limit
only.source§fn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>
fn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>
normalize-path
only.