Skip to content

Commit

Permalink
http2: support net.Server options
Browse files Browse the repository at this point in the history
Make `http2.createServer()` support `net.Server` options.

PR-URL: #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>
  • Loading branch information
lpinca authored and danbev committed May 23, 2019
1 parent d2cabee commit 165916b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
46 changes: 46 additions & 0 deletions test/parallel/test-http2-server-startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}));
}

0 comments on commit 165916b

Please sign in to comment.