Skip to content

using layer RequestDecompressionLayer with Router.merge #2219

Answered by davidpdrsn
yanns asked this question in Q&A
Discussion options

You must be logged in to vote

The issue is not merge, its the type annotation in

let other_router: Router = Router::new().route("/test", post(|| async {}));
//              ^^^^^^^^

The issue is that RequestDecompressionLayer requires a service that accepts a DecompressionBody<B> (where B is some generic body type).

But when you write other_router: Router you're setting the default body type param for Router which is B. Thus you're saying other_router: Router<(), axum::body::Body> (() is the default state). Router<(), axum::body::Body> doesn't accept DecompressionBody<B>, it only accepts axum::body::Body.

The solution is to leave off the type annotation and do

#[tokio::main]
async fn main() {
    let other_router = Ro…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@yanns
Comment options

yanns Sep 11, 2023
Collaborator Author

@yanns
Comment options

yanns Sep 11, 2023
Collaborator Author

@davidpdrsn
Comment options

@jplatte

This comment has been minimized.

@yanns
Comment options

yanns Sep 11, 2023
Collaborator Author

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