tower-rs / tower-http

HTTP specific Tower utilities.
680 stars 159 forks source link

Signature of the on_response closure #430

Closed zrll12 closed 10 months ago

zrll12 commented 10 months ago

The documents about trace layer gives the following example:

.on_response(|response: &Response<Body>, latency: Duration, _span: &Span| {
    tracing::debug!("response generated in {:?}", latency)
})

This will generate a error

expected closure signature `for<'a, 'b> fn(&'a Response<http_body::combinators::box_body::UnsyncBoxBody<axum::body::Bytes, axum::Error>>, Duration, &'b Span) -> _`
   found closure signature `for<'a, 'b> fn(&'a Response<Body>, Duration, &'b Span) -> _`

And could run if change to

.on_response(|response: &Response<http_body::combinators::UnsyncBoxBody<axum::body::Bytes, axum::Error>>, latency: Duration, _span: &Span| {
    //something
});

I wonder if there is a feature that make these two types compatible.

Also, is there a way to get the method and uri in the on_ response closure?