Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: support net.Server options #27782

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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();
}));
}