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>>
Available on crate feature propagate-header
only.
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>>
Available on crate feature add-extension
only.
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>>
Available on crate feature map-request-body
only.
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>>
Available on crate feature map-response-body
only.
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>>
Available on crate features compression-br
or compression-deflate
or compression-gzip
or compression-zstd
only.
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>>
Available on crate features decompression-br
or decompression-deflate
or decompression-gzip
or decompression-zstd
only.
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>>
Available on crate feature trace
only.
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>>
Available on crate feature trace
only.
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>>
Available on crate feature follow-redirect
only.
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>,
Available on crate feature sensitive-headers
only.
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>>
Available on crate feature sensitive-headers
only.
fn sensitive_request_headers( self, headers: Arc<[HeaderName]>, ) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>
sensitive-headers
only.Mark headers as sensitive on requests.
See tower_http::sensitive_headers
for more details.
Sourcefn sensitive_response_headers(
self,
headers: Arc<[HeaderName]>,
) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>
Available on crate feature sensitive-headers
only.
fn sensitive_response_headers( self, headers: Arc<[HeaderName]>, ) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>
sensitive-headers
only.Mark headers as sensitive on 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>>
Available on crate feature set-header
only.
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>>
Available on crate feature set-header
only.
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>>
Available on crate feature set-header
only.
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>>
Available on crate feature set-header
only.
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>>
Available on crate feature set-header
only.
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>>
Available on crate feature set-header
only.
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,
Available on crate feature request-id
only.
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>>
Available on crate feature request-id
only.
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>>
Available on crate feature catch-panic
only.
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>>
Available on crate feature limit
only.
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>>
Available on crate feature normalize-path
only.
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,
Available on crate feature request-id
only.
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>>
Available on crate feature request-id
only.
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
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.