-
Notifications
You must be signed in to change notification settings - Fork 721
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
feat(s2n-tls-hyper): Add support for negotiating HTTP/2 #4924
Conversation
8bd2b37
to
552530e
Compare
9139ddf
to
fcf21c3
Compare
fcf21c3
to
e87a725
Compare
8ec55f2
to
65aeac2
Compare
65aeac2
to
0220444
Compare
match conn.application_protocol() { | ||
// Inform hyper that HTTP/2 was negotiated in the ALPN. | ||
Some(b"h2") => connected.negotiated_h2(), | ||
_ => connected, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we could assert that the negotiated application protocol was something we expected here. However, we can't return an error since this function doesn't return an error. We could panic, however misbehaved servers could technically return whatever ALPN value they want, whether or not the client attempted to negotiate it. So panicking here seems wrong, since it's outside of the user's control. It seemed better to just attempt HTTP/1 if an unexpected protocol was negotiated.
ce94adf
to
a90e03a
Compare
// https://datatracker.ietf.org/doc/html/rfc7301#section-3.2 | ||
// In the event that the server supports no | ||
// protocols that the client advertises, then the server SHALL respond | ||
// with a fatal "no_application_protocol" alert. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Description of changes:
Currently s2n-tls-hyper can only negotiate HTTP/1. This PR adds support for HTTP/2.
HTTP/2 is negotiated at the TLS level, via the ALPN extension. After the hyper client completes the TLS handshake, the negotiated ALPN value is checked. If HTTP/2 was negotiated, HTTP/2 is enabled in hyper by updating the returned
Connected
struct.Call-outs:
I currently attempt to always negotiate HTTP/2 by just always sending HTTP/2 in the ALPN. This means that ALPN values manually set on the config will be ignored. I think this is fine though, since it seems like s2n-tls-hyper should be the one deciding which ALPN values to send. We can also later add a way to configure the ALPN in s2n-tls-hyper, if we need a way to opt-out of HTTP/2 or something.
Testing:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.