hyper-rustls icon indicating copy to clipboard operation
hyper-rustls copied to clipboard

how should I configure features to support http1, http2 and tls?

Open garypen opened this issue 3 years ago • 3 comments

Thanks for working on this crate. It's really useful. I do have an issue though:

If I add hyper-rustls to my Cargo.toml as follows:

hyper-rustls = { version = "0.23.0" }

I find that I can't compile my code:

        let connector = hyper_rustls::HttpsConnectorBuilder::new()
            .with_native_roots()
            .https_or_http()
            .enable_http2()
            .enable_http1()
            .build();

because I get this error:

error[E0599]: no method named `enable_http2` found for struct `HttpsConnectorBuilder` in the current scope
  --> apollo-router-core/src/services/tower_subgraph_service.rs:31:14
   |
31 |             .enable_http2()
   |              ^^^^^^^^^^^^ help: there is an associated function with a similar name: `enable_http1`

Reading through the documentation, I find references to features and modify my Cargo.toml so that:

hyper-rustls = { version = "0.23.0", features = ["http1", "http2", "tls12"] }

I then get this error:

error[E0599]: no method named `enable_http1` found for struct `HttpsConnectorBuilder<WantsProtocols3>` in the current scope
  --> apollo-router-core/src/services/tower_subgraph_service.rs:32:14
   |
32 |             .enable_http1()
   |              ^^^^^^^^^^^^ method not found in `HttpsConnectorBuilder<WantsProtocols3>`
   |
   = note: the method was found for
           - `HttpsConnectorBuilder<WantsProtocols1>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `apollo-router-core` due to previous error

Should it be possible to have both http2 and http1 enabled?

garypen avatar May 03 '22 08:05 garypen

Have you tried swapping .enable_http2() and .enable_http1()?

paolobarbolini avatar May 03 '22 08:05 paolobarbolini

Thanks for the really quick response and answer.

I thought I had, but apparently I hadn't. I just swapped them around and this compiles fine:

hyper-rustls = { version = "0.23.0", features = ["http1", "http2", "tls12"] }
        let connector = hyper_rustls::HttpsConnectorBuilder::new()
            .with_native_roots()
            .https_or_http()
            .enable_http1()
            .enable_http2()
            .build();

I guess I should have figured that out from the documentation somehow, but is there a way this requirement could be made clearer? Perhaps in the docs for both enable_http1 and enable_http2?

garypen avatar May 03 '22 08:05 garypen

Proposed an additional helper method in #171 that might make this nicer.

djc avatar May 09 '22 12:05 djc

The helper in #171 was merged and will be included in the next release, which should be published in the coming days.

cpu avatar Mar 31 '23 17:03 cpu