Trait tower_http::ServiceBuilderExt
source · [−]pub trait ServiceBuilderExt<L>: Sealed<L> + Sized {
Show 23 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<SharedClassifier<ServerErrorsAsFailures>>, L>>;
fn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, 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 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>> { ... }
}
Expand description
Extension trait that adds methods to tower::ServiceBuilder
for adding middleware from
tower-http.
Example
use http::{Request, Response, header::HeaderName};
use hyper::Body;
use std::{time::Duration, convert::Infallible};
use tower::{ServiceBuilder, ServiceExt, Service};
use tower_http::ServiceBuilderExt;
async fn handle(request: Request<Body>) -> Result<Response<Body>, Infallible> {
Ok(Response::new(Body::empty()))
}
let service = ServiceBuilder::new()
// Methods from tower
.timeout(Duration::from_secs(30))
// Methods from tower-http
.trace_for_http()
.compression()
.propagate_header(HeaderName::from_static("x-request-id"))
.service_fn(handle);
Required methods
fn 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.
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.Add some shareable value to request extensions.
See tower_http::add_extension
for more details.
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.Apply a transformation to the request body.
See tower_http::map_request_body
for more details.
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.Apply a transformation to the response body.
See tower_http::map_response_body
for more details.
fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
compression-br
or compression-deflate
or compression-gzip
only.Compresses response bodies.
See tower_http::compression
for more details.
fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
decompression-br
or decompression-deflate
or decompression-gzip
only.Decompress response bodies.
See tower_http::decompression
for more details.
fn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, L>>
fn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, 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.
fn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, L>>
fn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, 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.
fn 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.
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.Mark headers as sensitive on both requests and responses.
See tower_http::sensitive_headers
for more details.
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.Mark headers as sensitive on both requests.
See tower_http::sensitive_headers
for more details.
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.Mark headers as sensitive on both responses.
See tower_http::sensitive_headers
for more details.
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.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.
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.Append a header into the request.
If previous values exist, the header will have multiple values.
See tower_http::set_header
for more details.
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.Insert a header into the request, if the header is not already present.
See tower_http::set_header
for more details.
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.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.
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.Append a header into the response.
If previous values exist, the header will have multiple values.
See tower_http::set_header
for more details.
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.Insert a header into the response, if the header is not already present.
See tower_http::set_header
for more details.
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.Add request id header and extension.
See tower_http::request_id
for more details.
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.Propgate request ids from requests to responses.
See tower_http::request_id
for more details.
fn 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.
Provided methods
fn 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.
fn 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.
Implementations on Foreign Types
sourceimpl<L> ServiceBuilderExt<L> for ServiceBuilder<L>
impl<L> ServiceBuilderExt<L> for ServiceBuilder<L>
sourcefn propagate_header(
self,
header: HeaderName
) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>
fn propagate_header(
self,
header: HeaderName
) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>
propagate-header
only.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.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.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.sourcefn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>
compression-br
or compression-deflate
or compression-gzip
only.sourcefn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>
decompression-br
or decompression-deflate
or decompression-gzip
only.sourcefn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, L>>
fn trace_for_http(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, L>>
trace
only.sourcefn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, L>>
fn trace_for_grpc(
self
) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, L>>
trace
only.sourcefn follow_redirects(
self
) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>
fn follow_redirects(
self
) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>
follow-redirect
only.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.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.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.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.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.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.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.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.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.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.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.sourcefn catch_panic(
self
) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>
fn catch_panic(
self
) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>
catch-panic
only.