Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
58478d8
http2: add http fallback options to .createServer
hekike Oct 27, 2017
5ea29ef
http: add options to http.createServer()
Oct 19, 2017
ae2ebde
http2: add req and res options to server creation
Oct 5, 2017
28a2729
http2: use `_final` instead of `on('finish')`
addaleax Feb 7, 2018
8b234f5
doc: warn against concurrent http2stream.respondWithFD
addaleax Feb 13, 2018
c6a9abd
src: add nullptr check for session in DEBUG macro
danbev Feb 16, 2018
d85e5f4
doc: fix typo in http2.md
vsemozhetbyt Feb 19, 2018
55cf145
deps,src: align ssize_t ABI between Node & nghttp2
addaleax Feb 4, 2018
b1d95ec
http2: fix condition where data is lost
mcollina Feb 19, 2018
1029369
http2: send error text in case of ALPN mismatch
addaleax Feb 25, 2018
0379350
http2: use original error for cancelling pending streams
addaleax Feb 25, 2018
1f3ab4f
http2: fix endless loop when writing empty string
addaleax Feb 22, 2018
199d9a5
test: check endless loop while writing empty string
XadillaX Feb 11, 2018
10aaa74
http2: fix flaky test-http2-https-fallback
mcollina Mar 2, 2018
f165e9f
http2: no stream destroy while its data is on the wire
addaleax Feb 26, 2018
8daddfb
doc: add note about browsers and HTTP/2
styfle Mar 20, 2018
0137eb7
http2: remove some unnecessary next ticks
jasnell Mar 19, 2018
8f55971
doc: rename HTTP2 to HTTP/2
TimothyGu Mar 26, 2018
9c7bf7f
test: http2 stream.respond() error checks
trivikr Feb 19, 2018
519b063
http2: destroy() stream, upon errnoException
Mar 16, 2018
22eddf1
doc: guard against md list parsing edge case
vsemozhetbyt Mar 28, 2018
f5a2cd5
test: http2 errors on req.close()
trivikr Feb 18, 2018
af7c7cb
http2: callback valid check before closing request
trivikr Feb 28, 2018
3a890a8
doc, http2: add sections for server.close()
chrismilleruk Apr 4, 2018
4dc0b3c
doc: add Http2Session.connecting property
pietermees Apr 6, 2018
c83098a
http2: emit session connect on next tick
pietermees Apr 9, 2018
1f35b8f
src: expose uv.errmap to binding
joyeecheung Dec 25, 2017
d501138
util: implement util.getSystemErrorName()
joyeecheung Jan 16, 2018
a3754e7
errors: lazy load util in internal/errors.js
joyeecheung Jan 24, 2018
2179547
util: skip type checks in internal getSystemErrorName
joyeecheung Feb 3, 2018
d8b637f
errors: move error creation helpers to errors.js
joyeecheung Feb 3, 2018
74e3b14
errors: make message non-enumerable
BridgeAR Apr 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
http2: add http fallback options to .createServer
This adds the Http1IncomingMessage and Http1ServerReponse options
to http2.createServer().

Backport-PR-URL: #20456
PR-URL: #15752
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
  • Loading branch information
hekike authored and MylesBorins committed May 2, 2018
commit 58478d8307a1ed4379078fe00eec4cb198cf4307
10 changes: 10 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,10 @@ changes:
pr-url: https://github.com/nodejs/node/pull/16676
description: Added the `maxHeaderListPairs` option with a default limit of
128 header pairs.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/15752
description: Added the `Http1IncomingMessage` and `Http1ServerResponse`
option.
-->

* `options` {Object}
Expand Down Expand Up @@ -1704,6 +1708,12 @@ changes:
used to determine the padding. See [Using options.selectPadding][].
* `settings` {HTTP2 Settings Object} The initial settings to send to the
remote peer upon connection.
* `Http1IncomingMessage` {http.IncomingMessage} Specifies the IncomingMessage
class to used for HTTP/1 fallback. Useful for extending the original
`http.IncomingMessage`. **Default:** `http.IncomingMessage`
* `Http1ServerResponse` {http.ServerResponse} Specifies the ServerResponse
class to used for HTTP/1 fallback. Useful for extending the original
`http.ServerResponse`. **Default:** `http.ServerResponse`
* `onRequestHandler` {Function} See [Compatibility API][]
* Returns: {Http2Server}

Expand Down
15 changes: 14 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require('internal/util').assertCrypto();

const { async_id_symbol } = process.binding('async_wrap');
const http = require('http');
const binding = process.binding('http2');
const assert = require('assert');
const { Buffer } = require('buffer');
Expand Down Expand Up @@ -67,6 +68,8 @@ const NETServer = net.Server;
const TLSServer = tls.Server;

const kInspect = require('internal/util').customInspectSymbol;
const { kIncomingMessage } = require('_http_common');
const { kServerResponse } = require('_http_server');

const kAlpnProtocol = Symbol('alpnProtocol');
const kAuthority = Symbol('authority');
Expand Down Expand Up @@ -2442,8 +2445,11 @@ function connectionListener(socket) {

if (socket.alpnProtocol === false || socket.alpnProtocol === 'http/1.1') {
// Fallback to HTTP/1.1
if (options.allowHTTP1 === true)
if (options.allowHTTP1 === true) {
socket.server[kIncomingMessage] = options.Http1IncomingMessage;
socket.server[kServerResponse] = options.Http1ServerResponse;
return httpConnectionListener.call(this, socket);
}
// Let event handler deal with the socket
if (!this.emit('unknownProtocol', socket))
socket.destroy();
Expand Down Expand Up @@ -2474,6 +2480,13 @@ function initializeOptions(options) {
options.allowHalfOpen = true;
assertIsObject(options.settings, 'options.settings');
options.settings = Object.assign({}, options.settings);

// Used only with allowHTTP1
options.Http1IncomingMessage = options.Http1IncomingMessage ||
http.IncomingMessage;
options.Http1ServerResponse = options.Http1ServerResponse ||
http.ServerResponse;

return options;
}

Expand Down
90 changes: 90 additions & 0 deletions test/parallel/test-http2-https-fallback-http-server-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Flags: --expose-http2
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');

if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const url = require('url');
const tls = require('tls');
const http2 = require('http2');
const https = require('https');
const http = require('http');

const key = fixtures.readKey('agent8-key.pem');
const cert = fixtures.readKey('agent8-cert.pem');
const ca = fixtures.readKey('fake-startcom-root-cert.pem');

function onRequest(request, response) {
const { socket: { alpnProtocol } } = request.httpVersion === '2.0' ?
request.stream.session : request;
response.status(200);
response.end(JSON.stringify({
alpnProtocol,
httpVersion: request.httpVersion,
userAgent: request.getUserAgent()
}));
}

class MyIncomingMessage extends http.IncomingMessage {
getUserAgent() {
return this.headers['user-agent'] || 'unknown';
}
}

class MyServerResponse extends http.ServerResponse {
status(code) {
return this.writeHead(code, { 'Content-Type': 'application/json' });
}
}

// HTTP/2 & HTTP/1.1 server
{
const server = http2.createSecureServer(
{
cert,
key, allowHTTP1: true,
Http1IncomingMessage: MyIncomingMessage,
Http1ServerResponse: MyServerResponse
},
common.mustCall(onRequest, 1)
);

server.listen(0);

server.on('listening', common.mustCall(() => {
const { port } = server.address();
const origin = `https://localhost:${port}`;

// HTTP/1.1 client
https.get(
Object.assign(url.parse(origin), {
secureContext: tls.createSecureContext({ ca }),
headers: { 'User-Agent': 'node-test' }
}),
common.mustCall((response) => {
assert.strictEqual(response.statusCode, 200);
assert.strictEqual(response.statusMessage, 'OK');
assert.strictEqual(
response.headers['content-type'],
'application/json'
);

response.setEncoding('utf8');
let raw = '';
response.on('data', (chunk) => { raw += chunk; });
response.on('end', common.mustCall(() => {
const { alpnProtocol, httpVersion, userAgent } = JSON.parse(raw);
assert.strictEqual(alpnProtocol, false);
assert.strictEqual(httpVersion, '1.1');
assert.strictEqual(userAgent, 'node-test');

server.close();
}));
})
);
}));
}