Prioritize H2 via ALPN. #28
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I set ALPN on the rustls config so the server actually advertises "h2". Without that, browsers were sticking to HTTP/1.1 even though .http2() was enabled. Switching from the self-signed cert to Let’s Encrypt made it obvious ALPN wasn’t set, so HTTP/2 never negotiated. This fixes it by explicitly advertising h2, with fallbacks to HTTP/1.1, then 1.0, then 0.9 for odd clients.
I changed the error handling to get this in. It would be better to add a dedicated error for ALPN/TLS config (see src/error.rs lines 36–37) instead of the generic path I used but i don't really know what to set.
Also, if you add h3 or httpbis later it would be nice to have a way to change the HTTP versions priorities.