Trait tower_http::ServiceBuilderExt

source ·
pub trait ServiceBuilderExt<L>: Sealed<L> + Sized {
    // Required methods
    fn map_response_body<F>(
        self,
        f: F
    ) -> ServiceBuilder<Stack<MapResponseBodyLayer<F>, L>>;
    fn trace_for_http(
        self
    ) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<ServerErrorsAsFailures>>, L>>;
    fn trace_for_grpc(
        self
    ) -> ServiceBuilder<Stack<TraceLayer<SharedClassifier<GrpcErrorsAsFailures>>, 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§

source

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

Apply a transformation to the response body.

See tower_http::map_response_body for more details.

source

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

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

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

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

Implementors§