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<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 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>> { ... }
}
Available on crate feature 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 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§

source

fn propagate_header( self, header: HeaderName ) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>

Available on crate feature propagate-header only.

Propagate a header from the request to the response.

See tower_http::propagate_header for more details.

source

fn add_extension<T>( self, value: T ) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>

Available on crate feature add-extension only.

Add some shareable value to request extensions.

See tower_http::add_extension for more details.

source

fn map_request_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>

Available on crate feature map-request-body only.

Apply a transformation to the request body.

See tower_http::map_request_body for more details.

source

fn map_response_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>

Available on crate feature map-response-body only.

Apply a transformation to the response body.

See tower_http::map_response_body for more details.

source

fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>

Available on crate features compression-br or compression-deflate or compression-gzip or compression-zstd only.

Compresses response bodies.

See tower_http::compression for more details.

source

fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>

Available on crate features decompression-br or decompression-deflate or decompression-gzip or decompression-zstd only.

Decompress response bodies.

See tower_http::decompression for more details.

source

fn trace_for_http( self ) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, L>>

Available 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.

source

fn trace_for_grpc( self ) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, L>>

Available 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.

source

fn follow_redirects( self ) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>

Available on crate feature follow-redirect only.

Follow redirect resposes using the Standard policy.

See tower_http::follow_redirect for more details.

source

fn sensitive_headers<I>( self, headers: I ) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>where I: IntoIterator<Item = HeaderName>,

Available on crate feature sensitive-headers only.

Mark headers as sensitive on both requests and responses.

See tower_http::sensitive_headers for more details.

source

fn sensitive_request_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>

Available on crate feature sensitive-headers only.

Mark headers as sensitive on both requests.

See tower_http::sensitive_headers for more details.

source

fn sensitive_response_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>

Available on crate feature sensitive-headers only.

Mark headers as sensitive on both responses.

See tower_http::sensitive_headers for more details.

source

fn override_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>

Available 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.

source

fn append_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>

Available 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.

source

fn 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.

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

See tower_http::set_header for more details.

source

fn override_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>

Available 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.

source

fn append_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>

Available 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.

source

fn 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.

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

See tower_http::set_header for more details.

source

fn 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.

Add request id header and extension.

See tower_http::request_id for more details.

source

fn propagate_request_id( self, header_name: HeaderName ) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>

Available on crate feature request-id only.

Propgate request ids from requests to responses.

See tower_http::request_id for more details.

source

fn catch_panic( self ) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>

Available on crate feature catch-panic only.

Catch panics and convert them into 500 Internal Server responses.

See tower_http::catch_panic for more details.

source

fn request_body_limit( self, limit: usize ) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>

Available on crate feature limit only.

Intercept requests with over-sized payloads and convert them into 413 Payload Too Large responses.

See tower_http::limit for more details.

source

fn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>

Available on crate feature normalize-path only.

Remove trailing slashes from paths.

See tower_http::normalize_path for more details.

Provided Methods§

source

fn 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.

Add request id header and extension, using x-request-id as the header name.

See tower_http::request_id for more details.

source

fn propagate_x_request_id( self ) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>

Available 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§

source§

impl<L> ServiceBuilderExt<L> for ServiceBuilder<L>

source§

fn propagate_header( self, header: HeaderName ) -> ServiceBuilder<Stack<PropagateHeaderLayer, L>>

Available on crate feature propagate-header only.
source§

fn add_extension<T>( self, value: T ) -> ServiceBuilder<Stack<AddExtensionLayer<T>, L>>

Available on crate feature add-extension only.
source§

fn map_request_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapRequestBodyLayer<F>, L>>

Available on crate feature map-request-body only.
source§

fn map_response_body<F>( self, f: F ) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>

Available on crate feature map-response-body only.
source§

fn compression(self) -> ServiceBuilder<Stack<CompressionLayer, L>>

Available on crate features compression-br or compression-deflate or compression-gzip or compression-zstd only.
source§

fn decompression(self) -> ServiceBuilder<Stack<DecompressionLayer, L>>

Available on crate features decompression-br or decompression-deflate or decompression-gzip or decompression-zstd only.
source§

fn trace_for_http( self ) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, L>>

Available on crate feature trace only.
source§

fn trace_for_grpc( self ) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, L>>

Available on crate feature trace only.
source§

fn follow_redirects( self ) -> ServiceBuilder<Stack<FollowRedirectLayer<Standard>, L>>

Available on crate feature follow-redirect only.
source§

fn sensitive_headers<I>( self, headers: I ) -> ServiceBuilder<Stack<SetSensitiveHeadersLayer, L>>where I: IntoIterator<Item = HeaderName>,

Available on crate feature sensitive-headers only.
source§

fn sensitive_request_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveRequestHeadersLayer, L>>

Available on crate feature sensitive-headers only.
source§

fn sensitive_response_headers( self, headers: Arc<[HeaderName]> ) -> ServiceBuilder<Stack<SetSensitiveResponseHeadersLayer, L>>

Available on crate feature sensitive-headers only.
source§

fn override_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>

Available on crate feature set-header only.
source§

fn append_request_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetRequestHeaderLayer<M>, L>>

Available on crate feature set-header only.
source§

fn 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.
source§

fn override_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>

Available on crate feature set-header only.
source§

fn append_response_header<M>( self, header_name: HeaderName, make: M ) -> ServiceBuilder<Stack<SetResponseHeaderLayer<M>, L>>

Available on crate feature set-header only.
source§

fn 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.
source§

fn 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.
source§

fn propagate_request_id( self, header_name: HeaderName ) -> ServiceBuilder<Stack<PropagateRequestIdLayer, L>>

Available on crate feature request-id only.
source§

fn catch_panic( self ) -> ServiceBuilder<Stack<CatchPanicLayer<DefaultResponseForPanic>, L>>

Available on crate feature catch-panic only.
source§

fn request_body_limit( self, limit: usize ) -> ServiceBuilder<Stack<RequestBodyLimitLayer, L>>

Available on crate feature limit only.
source§

fn trim_trailing_slash(self) -> ServiceBuilder<Stack<NormalizePathLayer, L>>

Available on crate feature normalize-path only.

Implementors§