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<HttpMakeClassifier>, L>>;
    fn trace_for_grpc(
        self,
    ) -> ServiceBuilder<Stack<TraceLayer<GrpcMakeClassifier>, 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 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§

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<HttpMakeClassifier>, 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<GrpcMakeClassifier>, 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§