Skip to content
Discussion options

You must be logged in to vote

Without testing the setup, what I think happens is that the trace layer changes the body type of the response, which the optional layer does not support though it doesn't seem to be documented.

This doesn't work:

    let app = Router::new()
        .layer(option_layer(Some(TraceLayer::new_for_http())))
        .with_state(state);

while this does:

    let app = Router::new()
        .layer(option_layer(Some((
            tower_http::map_response_body::MapResponseBodyLayer::new(axum::body::Body::new),
            TraceLayer::new_for_http(),
        ))))
        .with_state(state);

What happens is optinal_layer creates Either<T, Idnetity> which implements Layer but the returned service imple…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@barskern
Comment options

@mladedav
Comment options

@barskern
Comment options

Answer selected by barskern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3438 on August 18, 2025 18:28.