diff options
author | Luigi Pinca <luigipinca@gmail.com> | 2019-05-20 14:59:20 +0200 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-05-23 05:35:19 +0200 |
commit | 165916b1f3ec094b1694bd5a056c2fc5e56027c2 (patch) | |
tree | 416cca009bcc9ff7573a19ecd27b0bafa367030e | |
parent | d2cabee64c60a7d6e2023dfb60c26cb66dc2eaa4 (diff) | |
download | android-node-v8-165916b1f3ec094b1694bd5a056c2fc5e56027c2.tar.gz android-node-v8-165916b1f3ec094b1694bd5a056c2fc5e56027c2.tar.bz2 android-node-v8-165916b1f3ec094b1694bd5a056c2fc5e56027c2.zip |
http2: support net.Server options
Make `http2.createServer()` support `net.Server` options.
PR-URL: https://github.com/nodejs/node/pull/27782
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
-rw-r--r-- | doc/api/http2.md | 6 | ||||
-rw-r--r-- | lib/internal/http2/core.js | 5 | ||||
-rw-r--r-- | test/parallel/test-http2-server-startup.js | 46 |
3 files changed, 55 insertions, 2 deletions
diff --git a/doc/api/http2.md b/doc/api/http2.md index 5ba4943a4d..8176b83e9f 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -1912,6 +1912,10 @@ error will be thrown. <!-- YAML added: v8.4.0 changes: + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/27782 + description: The `options` parameter now supports `net.createServer()` + options. - version: v8.9.3 pr-url: https://github.com/nodejs/node/pull/17105 description: Added the `maxOutstandingPings` option with a default limit of @@ -1987,6 +1991,7 @@ changes: `Http2ServerResponse` class to use. Useful for extending the original `Http2ServerResponse`. **Default:** `Http2ServerResponse`. + * ...: Any [`net.createServer()`][] option can be provided. * `onRequestHandler` {Function} See [Compatibility API][] * Returns: {Http2Server} @@ -3466,6 +3471,7 @@ following additional properties: [`http2.createServer()`]: #http2_http2_createserver_options_onrequesthandler [`http2session.close()`]: #http2_http2session_close_callback [`http2stream.pushStream()`]: #http2_http2stream_pushstream_headers_options_callback +[`net.createServer()`]: net.html#net_net_createserver_options_connectionlistener [`net.Server.close()`]: net.html#net_server_close_callback [`net.Socket.bufferSize`]: net.html#net_socket_buffersize [`net.Socket.prototype.ref()`]: net.html#net_socket_ref diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index bd8639a6ea..e23be01fa4 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -2697,8 +2697,9 @@ class Http2SecureServer extends TLSServer { class Http2Server extends NETServer { constructor(options, requestListener) { - super(connectionListener); - this[kOptions] = initializeOptions(options); + options = initializeOptions(options); + super(options, connectionListener); + this[kOptions] = options; this.timeout = 0; this.on('newListener', setupCompat); if (typeof requestListener === 'function') diff --git a/test/parallel/test-http2-server-startup.js b/test/parallel/test-http2-server-startup.js index 4ebcc21c27..c94abd2c22 100644 --- a/test/parallel/test-http2-server-startup.js +++ b/test/parallel/test-http2-server-startup.js @@ -10,6 +10,7 @@ const commonFixtures = require('../common/fixtures'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const http2 = require('http2'); const tls = require('tls'); const net = require('net'); @@ -48,6 +49,25 @@ server.on('error', common.mustNotCall()); })); } +// Test that `http2.createServer()` supports `net.Server` options. +{ + const server = http2.createServer({ allowHalfOpen: true }); + + server.on('connection', common.mustCall((socket) => { + assert.strictEqual(socket.allowHalfOpen, true); + socket.end(); + server.close(); + })); + + assert.strictEqual(server.allowHalfOpen, true); + + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const socket = net.connect(port, common.mustCall()); + socket.resume(); + })); +} + // Test the secure server socket timeout. { let client; @@ -67,3 +87,29 @@ server.on('error', common.mustNotCall()); }, common.mustCall()); })); } + +// Test that `http2.createSecureServer()` supports `net.Server` options. +{ + const server = http2.createSecureServer({ + allowHalfOpen: true, + ...options + }); + + server.on('secureConnection', common.mustCall((socket) => { + assert.strictEqual(socket.allowHalfOpen, true); + socket.end(); + server.close(); + })); + + assert.strictEqual(server.allowHalfOpen, true); + + server.listen(0, common.mustCall(() => { + const port = server.address().port; + const socket = tls.connect({ + port: port, + rejectUnauthorized: false, + ALPNProtocols: ['h2'] + }, common.mustCall()); + socket.resume(); + })); +} |