Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

http2: ALPN fallback to HTTP/1.1 #125

Closed
wants to merge 8 commits into from

Conversation

sebdeckers
Copy link
Contributor

@sebdeckers sebdeckers commented May 16, 2017

Fixes #122

Well then, this was a lot easier than I thought it would be. 😌

  • Deprecate NPN since this is not part of the HTTP/2 standard (and poorly documented AFAICT).
  • Announce ALPN as h2 or http/1.1, as per IANA-registered protocol IDs.
  • For backwards compatibility pass the non-HTTP/2 socket to the HTTP/1.1 parser. This then emits request events on the Http2SecureServer instance. Analogous to the https module.

Note 1: Some other tests are failing. Not sure if related to this patch. TIL --expose-internals

Note 2: Only doing fallback to https clients. Not for plaintext http since ALPN is inherently TLS-only. Should use the magic number to sniff plaintext http.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

http2

mcollina

This comment was marked as off-topic.

mcollina

This comment was marked as off-topic.

@sebdeckers
Copy link
Contributor Author

@mcollina The only problem I am seeing in this is "how do a user know if the current request is HTTP1.1 or HTTP2"?

message.httpVersion

request.httpVersion; // "2.0" or "1.1" or "1.0" etc.

@mcollina
Copy link
Member

@sebdeckers can you add it to the test? also with an http2 request, so that we show the difference.

@mcollina
Copy link
Member

@mikeal you had some good opinions on the design of this step of the API. What do you think?

@sebdeckers
Copy link
Contributor Author

@mcollina I've created an option called allowHTTP1. It can be passed to Http2SecureServer. The default value is true. Setting to false prevents the ALPN HTTP/1.1 fallback. This should be documented, perhaps when #102 lands.

Tests cover every combination of https/http2 clients against servers with/without ALPN fallback. Also explicitly reporting the httpVersion from server to the client.

@jasnell
Copy link
Member

jasnell commented May 16, 2017

fyi... needs a rebase :-)

@sebdeckers
Copy link
Contributor Author

@jasnell Nice, only took me a few minutes this time. Starting to get the hang of git cherry-pick. 😎

@sebdeckers
Copy link
Contributor Author

Nits and code issues aside, this implementation hinges on http._connectionListener.

Con

  • It has an underscore prefix and is not documented. This means it is not a public interface?
  • node-spdy and node-http2 extend https.Server. I don't know if we want to make Http2SecureServer extend https.Server?

Pro

  • require('https') imports http._connectionListener which imports it from require('_http_server'). This may imply that http._connectionListener is a public interface? At least for core modules?
  • Core modules could import _connectionListener directly from require('_http_server'). Then it stays private, but somewhat couples http2 and http modules.

See also: nodejs/node#2017 (comment)

mcollina

This comment was marked as off-topic.

@mcollina
Copy link
Member

It has an underscore prefix and is not documented. This means it is not a public interface?

I think overall this uses less of the internals compared to node-spdy and node-http2, so ok for me.

node-spdy and node-http2 extend https.Server. I don't know if we want to make Http2SecureServer extend https.Server?

IMHO that causes most of the issues in those modules. This is a clean implementation so no.

require('https') imports http._connectionListener which imports it from require('_http_server'). This may imply that http._connectionListener is a public interface? At least for core modules?

I think we can just import from _http_server.js, the function can still be underscored. How about we add a comment there?

Core modules could import _connectionListener directly from require('_http_server'). Then it stays private, but somewhat couples http2 and http modules.

Coupling is needed if we want to support both http1 and http2.

mcollina

This comment was marked as off-topic.

mcollina

This comment was marked as off-topic.

mcollina

This comment was marked as off-topic.

mcollina

This comment was marked as off-topic.

@sebdeckers sebdeckers mentioned this pull request May 17, 2017
4 tasks
@sebdeckers
Copy link
Contributor Author

(Rebased again)

jasnell

This comment was marked as off-topic.

jasnell

This comment was marked as off-topic.

@mcollina
Copy link
Member

Landed as 6232681

@mcollina mcollina closed this May 18, 2017
mcollina pushed a commit that referenced this pull request May 18, 2017
Support the upgrade path from https to http2.

PR-URL: #125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
mcollina pushed a commit that referenced this pull request May 18, 2017
Support the upgrade path from https to http2.

PR-URL: #125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@mcollina
Copy link
Member

My mistake, I force-pushed 5cc2b2a.

mcollina pushed a commit to mcollina/http2 that referenced this pull request May 18, 2017
Support the upgrade path from https to http2.

PR-URL: nodejs#125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell pushed a commit that referenced this pull request May 19, 2017
Support the upgrade path from https to http2.

PR-URL: #125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@sebdeckers sebdeckers deleted the alpn-h1-fallback branch May 20, 2017 15:05
jasnell pushed a commit that referenced this pull request May 31, 2017
Support the upgrade path from https to http2.

PR-URL: #125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell pushed a commit to jasnell/http2-1 that referenced this pull request Jun 22, 2017
Support the upgrade path from https to http2.

PR-URL: nodejs#125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell pushed a commit to jasnell/http2-1 that referenced this pull request Jul 10, 2017
Support the upgrade path from https to http2.

PR-URL: nodejs#125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jasnell pushed a commit to jasnell/http2-1 that referenced this pull request Jul 14, 2017
Support the upgrade path from https to http2.

PR-URL: nodejs#125
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http2: starting HTTP/2 with TLS ALPN
3 participants