-
Some prior context, but I'll describe the situation fully here: #3956. I'm building a proxy using Hyper. We run it in GCP Cloud Run. I'm building my client like this, so we only support HTTP/2 requests: pub fn build_http_client() -> HyperClient {
Client::builder(TokioExecutor::new())
.http2_only(true)
.build::<_, axum::body::Body>(hyper_tls::HttpsConnector::new()) I run a HTTP/2-only server like this:
I then configure my proxy like this:
We can confirm that https://myapi.com supports HTTP/2 requests:
Now I run my proxy. I send a request to my proxy to hit endpoint1 locally like this:
Perfect, this is working great. Now let's hit endpoint2:
Ruh roh. This is what we see from the proxy (abridged, full logs here): {"target":"hyper_util::client::legacy::connect::http","message":"connecting to 34.111.219.107:443"}
{"target":"hyper_util::client::legacy::connect::http","message":"connected to 34.111.219.107:443"}
{"target":"h2::proto::connection","message":"Connection::poll; connection error","error":"GoAway(b\"\", FRAME_SIZE_ERROR, Library)"}
{"target":"h2::codec::framed_write","message":"send","frame":"GoAway { error_code: FRAME_SIZE_ERROR, last_stream_id: StreamId(0) }"}
{"target":"h2::proto::connection","message":"Connection::poll; connection error","error":"GoAway(b\"\", FRAME_SIZE_ERROR, Library)"}
{"target":"hyper_util::client::legacy::client","message":"client connection error: http2 error"}
{"target":"tower_http::trace::on_failure","message":"response failed","classification":"Status code: 500 Internal Server Error","latency":"132 ms"} My suspicion is that the upstream can handle HTTP/2, but it can't handle HTTP/2 cleartext. I would've maybe naively hoped that when I send the request off with Hyper, it magically wraps it back up into a normal HTTP/2 request. Is there a way to get this to work, assuming my diagnosis of the issue is correct? Another possible issue is the upstream only supports HTTP/2 after first upgrading to it from HTTP/1.1. I was hoping enabling In short if I receive a HTTP/2 request (h2c or not) I want to be able to proxy it to a https upstream that supports HTTP/2 (though perhaps only via an upgrade, I'm not exactly sure). My relevant dependencies: axum = { version = "0.7.4", features = ["http2", "ws"] }
http = "1.3.1"
http-body = "1.0.1"
http-body-util = "0.1.3"
hyper = { version = "1.7.0" }
hyper-tls = { version = "0.6.0", features = ["alpn"] }
hyper-util = "0.1.17" |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Note that if I don't set
|
Beta Was this translation helpful? Give feedback.
-
Okay I see this comment for
So the question is just how to make this happen. Like I mentioned earlier, I thought https://docs.rs/hyper-tls/latest/hyper_tls with the alpn feature enabled would handle this. |
Beta Was this translation helpful? Give feedback.
Okay I was getting a million things mixed up but I think I've got it all sorted finally.
With the below config I can receive HTTP/2 requests over http:// requests, but I'm unable to send HTTP/2 requests to an upstream over http://. With the client described above, I get this error in the logs:
However if I use this client it works:
So in summary, here's what you do.
Build two clients: