-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/net/http2/h2c: H2C handler uses incorrect headers to detect upgrade #45785
Comments
My colleague, @ameowlia, pointed out that Section 3.2.1 of the spec does say that
Still, this feels like an odd choice for detecting For comparison, I testing the same request against a simple Python server that supports #!/usr/bin/env python3
from quart import Quart, request
app = Quart(__name__)
@app.route("/")
async def hello():
return f"Hello, {request.full_path}; HTTP Version: {request.http_version}."
if __name__ == "__main__":
app.run(port=8081) It successfully upgraded without the $ curl localhost:8081 -H "Upgrade: h2c" -H "HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA" -vvv
* Trying 127.0.0.1:8081...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET / HTTP/1.1
> Host: localhost:8081
> User-Agent: curl/7.68.0
> Accept: */*
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 101
< date: Mon, 26 Apr 2021 20:54:51 GMT
< server: hypercorn-h11
< connection: upgrade
< upgrade: h2c |
- Golang h2c package doesn't play well with reverse proxy due to golang/go#45785
cc @fraenkel |
I don't believe this is an issue given that this is following the spec as identified above.
|
Based on that, should go/src/net/http/httputil/reverseproxy.go Lines 272 to 277 in ce92a20
Otherwise, it seems impossible to implement the H2C upgrade flow spanning a |
I see why it makes sense to strip Would you be open to making the preserved headers configurable on |
Closing as this appears to be working as intended. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Running a simple
h2c
server:What did you expect to see?
Based on my reading of RFC 7540, Section 3.2, the required headers for an
h2c
upgrade areUpgrade: h2c
andHTTP2-Settings
:Curling with those headers, I would expect to receive a
HTTP/1.1 101 Switching Protocols
response.What did you see instead?
The h2c handler does not accept the upgrade:
This is because the
h2c
package is not checking the appropriate headers:Source: https://github.com/golang/net/blob/5f58ad60dda6b6eba34c424201d17c9fdc37953d/http2/h2c/h2c.go#L373-L378
While the
Connection: HTTP2-Settings
header does appear in the example in Section 3.2, I can't find anything in the spec that says it is required or that it should be used to detecth2c
upgrades.After adding the
Connection: HTTP2-Settings
header, theh2c
upgrade succeeds:This is causing problems because we are running our H2C apps behind a
httputil.ReverseProxy
, which removesConnection
headers, thereby blocking theh2c
upgrade.The text was updated successfully, but these errors were encountered: