Skip to content

Axum middleware mismatch on types #771

Closed
@wduminy

Description

@wduminy

I am upgrading from lambda_http 0.8 to 0.9.0
As a consequence, I also upgraded to axum 0.7.3`

I have a compile error on axum middleware:

Here is a minimal example:

pub async fn mw_sample_1(mut req: lambda_http::Request, next: Next) -> impl IntoResponse {
    next.run(req).await
}

It gives me this error:

error: mismatched types
label: arguments to this method are incorrect
note: `lambda_http::Body` and `axum::body::Body` have similar names, but are actually distinct types
label: arguments to this method are incorrect
note: `lambda_http::Body` is defined in crate `aws_lambda_events`
label: arguments to this method are incorrect
note: `axum::body::Body` is defined in crate `axum_core`
label: arguments to this method are incorrect
note: method defined here
label: arguments to this method are incorrect

If I change the code to this, the error goes away (as expected)

pub async fn mw_sample_2(mut req: axum::extract::Request, next: Next) -> impl IntoResponse {
    next.run(req).await
}

In my middleware, I need the lambda_http::Request.

Before the upgrade, the code looked like this:

pub async fn mw_sample_old(
    mut req: lambda_http::Request,
    next: Next<lambda_http::Body>,
) -> impl IntoResponse {
    next.run(req).await
}

Am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions