This repository has been archived by the owner on Sep 17, 2019. It is now read-only.
Support for HTTP/1.1 Upgrade ala Section 3.2 of the new soon-to-be RFC #48
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.
The following PR adds support for HTTP/1.1 upgrading ala Section 3.2.
The public interface for this is quite similar to
ConfigureServer
:Internally this is performed by cloning
h2serv
before callinghttp2.ConfigureServer()
and hooking its handler. When a request is detected which meets the upgrade requirements (Connection, Upgrade and HTTP2-Settings headers), the settings payload is decoded, the HTTP/1.1 portion of the upgrade is finalized, the connection is flushed and then hijacked. Finally, the hijacked connection is passed off to http2'shandleConn
.In order to facilitate injection of a hijacked net.Conn into http2's state machine some minor changes to server.go were made:
handleConn()
was refactored slightly by adding a new func:newConn()
which takes an optional pre-state []Setting slice and an upgrade callback function.serverConn
struct: a single-use upgrade channel which returns a func() that will be called once all settings frames have been ack'd. This callback is used to mock the original HTTP/1.1 request as a header frame payload on the half-closed stream id 1 (as per the spec). A final call toprocessHeaderBlockFragment()
triggers downstream application request processing as per usual.NOTE: Because the spec includes the dubious requirement that any request entity bodies must be read in-full before the protocol upgrade can begin, any attempts to transmit a request body are detected and will result in a silent failure to upgrade and a fallback to HTTP/1.1 handling.
This has been tested using Curl 7.42.0-DEV built against nghttp2/0.7.12-DEV as well as nghttp2 itself. Unit tests are provided which require docker & gohttp2/curl (via http2_test.go).