Skip to content

Unable to find Tower middleware signature constraints that works with both Axum and Hyper #3508

@francoposa

Description

@francoposa

Version
hyper 1, http 1

Platform
Linux thinkpad-z13 6.6.6-1-default #1 SMP PREEMPT_DYNAMIC Mon Dec 11 09:46:39 UTC 2023 (a946a9f) x86_64 x86_64 x86_64 GNU/Linux

Description
Attempting to update a tower middleware to work with axum 0.7 and hyper 1.0
Previously works with axum 0.6 and hyper 0.14

I had to unconstrain the Body parameter for Service to be accepted by axum, but now hyper 0.14 and hyper 1.0 won't accept it:
https://github.com/francoposa/tower-otel-http-metrics/pull/4/files

I based the generics signatures off of the tower-http request-id middleware in order to get it working with axum 0.7 again.

Axum 0.7 server code that now works with the updated middleware:
https://github.com/francoposa/tower-otel-http-metrics/blob/axum-0.7-compatibility/examples/axum-http-service/src/main.rs

Hyper 1.0 server code that won't work with the updated middleware or the old middleware:
https://github.com/francoposa/tower-otel-http-metrics/blob/axum-0.7-compatibility/examples/tower-http-service/src/main.rs

I also tried the hyper 1.0 server guide, and get the same issue - in fact the tower http request ID middleware also has the same issue.
I thus far have not found any middleware code examples anywhere that work with both axum 0.7 and hyper 1.0.

error[E0277]: the trait bound `HTTPMetricsService<ServiceFn<fn(hyper::Request<hyper::body::Incoming>) -> impl Future<Output = Result<Response<http_body_util::Full<hyper::body::Bytes>>, Infallible>> {handle}>>: hyper::service::Service<hyper::Request<hyper::body::Incoming>>` is not satisfied
  --> src/main.rs:86:18
   |
86 |                 .serve_connection(io, service)
   |                  ^^^^^^^^^^^^^^^^ the trait `hyper::service::Service<hyper::Request<hyper::body::Incoming>>` is not implemented for `HTTPMetricsService<ServiceFn<fn(hyper::Request<hyper::body::Incoming>) -> impl Future<Output = Result<Response<http_body_util::Full<hyper::body::Bytes>>, Infallible>> {handle}>>`
   |
   = help: the trait `hyper::service::Service<hyper::Request<ReqBody>>` is implemented for `service::util::ServiceFn<F, ReqBody>`
   = note: required for `HTTPMetricsService<ServiceFn<fn(Request<Incoming>) -> impl Future<Output = Result<..., ...>> {handle}>>` to implement `HttpService<hyper::body::Incoming>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug. Something is wrong. This is bad!

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions