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

This is supported on crate feature propagate-header only.

Propagate a header from the request to the response.

See tower_http::propagate_header for more details.

This is supported on crate feature add-extension only.

Add some shareable value to request extensions.

See tower_http::add_extension for more details.

This is supported on crate feature map-request-body only.

Apply a transformation to the request body.

See tower_http::map_request_body for more details.

This is supported on crate feature map-response-body only.

Apply a transformation to the response body.

See tower_http::map_response_body for more details.

This is supported on crate features compression-br or compression-deflate or compression-gzip only.

Compresses response bodies.

See tower_http::compression for more details.

This is supported on crate features decompression-br or decompression-deflate or decompression-gzip only.

Decompress response bodies.

See tower_http::decompression for more details.

This is supported on crate feature 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.

This is supported on crate feature 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.

This is supported on crate feature follow-redirect only.

Follow redirect resposes using the Standard policy.

See tower_http::follow_redirect for more details.

This is supported on crate feature sensitive-headers only.

Mark headers as sensitive on both requests and responses.

See tower_http::sensitive_headers for more details.

This is supported on crate feature sensitive-headers only.

Mark headers as sensitive on both requests.

See tower_http::sensitive_headers for more details.

This is supported on crate feature sensitive-headers only.

Mark headers as sensitive on both responses.

See tower_http::sensitive_headers for more details.

This is supported on crate feature 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.

This is supported on crate feature 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.

This is supported on crate feature set-header only.

Insert a header into the request, if the header is not already present.

See tower_http::set_header for more details.

This is supported on crate feature 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.

This is supported on crate feature 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.

This is supported on crate feature set-header only.

Insert a header into the response, if the header is not already present.

See tower_http::set_header for more details.

This is supported on crate feature request-id only.

Add request id header and extension.

See tower_http::request_id for more details.

This is supported on crate feature request-id only.

Propgate request ids from requests to responses.

See tower_http::request_id for more details.

This is supported on crate feature catch-panic only.

Catch panics and convert them into 500 Internal Server responses.

See tower_http::catch_panic for more details.

Provided methods

This is supported on crate feature 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.

This is supported on crate feature 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

This is supported on crate feature propagate-header only.
This is supported on crate feature add-extension only.
This is supported on crate feature map-request-body only.
This is supported on crate feature map-response-body only.
This is supported on crate features compression-br or compression-deflate or compression-gzip only.
This is supported on crate features decompression-br or decompression-deflate or decompression-gzip only.
This is supported on crate feature trace only.
This is supported on crate feature trace only.
This is supported on crate feature follow-redirect only.
This is supported on crate feature sensitive-headers only.
This is supported on crate feature sensitive-headers only.
This is supported on crate feature sensitive-headers only.
This is supported on crate feature set-header only.
This is supported on crate feature set-header only.
This is supported on crate feature set-header only.
This is supported on crate feature set-header only.
This is supported on crate feature set-header only.
This is supported on crate feature set-header only.
This is supported on crate feature request-id only.
This is supported on crate feature request-id only.
This is supported on crate feature catch-panic only.

Implementors