Skip to content

Commit 165916b

Browse files
lpincadanbev
authored andcommitted
http2: support net.Server options
Make `http2.createServer()` support `net.Server` options. PR-URL: #27782 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent d2cabee commit 165916b

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

doc/api/http2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,10 @@ error will be thrown.
19121912
<!-- YAML
19131913
added: v8.4.0
19141914
changes:
1915+
- version: REPLACEME
1916+
pr-url: https://github.com/nodejs/node/pull/27782
1917+
description: The `options` parameter now supports `net.createServer()`
1918+
options.
19151919
- version: v8.9.3
19161920
pr-url: https://github.com/nodejs/node/pull/17105
19171921
description: Added the `maxOutstandingPings` option with a default limit of
@@ -1987,6 +1991,7 @@ changes:
19871991
`Http2ServerResponse` class to use.
19881992
Useful for extending the original `Http2ServerResponse`.
19891993
**Default:** `Http2ServerResponse`.
1994+
* ...: Any [`net.createServer()`][] option can be provided.
19901995
* `onRequestHandler` {Function} See [Compatibility API][]
19911996
* Returns: {Http2Server}
19921997

@@ -3466,6 +3471,7 @@ following additional properties:
34663471
[`http2.createServer()`]: #http2_http2_createserver_options_onrequesthandler
34673472
[`http2session.close()`]: #http2_http2session_close_callback
34683473
[`http2stream.pushStream()`]: #http2_http2stream_pushstream_headers_options_callback
3474+
[`net.createServer()`]: net.html#net_net_createserver_options_connectionlistener
34693475
[`net.Server.close()`]: net.html#net_server_close_callback
34703476
[`net.Socket.bufferSize`]: net.html#net_socket_buffersize
34713477
[`net.Socket.prototype.ref()`]: net.html#net_socket_ref

lib/internal/http2/core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,8 +2697,9 @@ class Http2SecureServer extends TLSServer {
26972697

26982698
class Http2Server extends NETServer {
26992699
constructor(options, requestListener) {
2700-
super(connectionListener);
2701-
this[kOptions] = initializeOptions(options);
2700+
options = initializeOptions(options);
2701+
super(options, connectionListener);
2702+
this[kOptions] = options;
27022703
this.timeout = 0;
27032704
this.on('newListener', setupCompat);
27042705
if (typeof requestListener === 'function')

test/parallel/test-http2-server-startup.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const commonFixtures = require('../common/fixtures');
1010
if (!common.hasCrypto)
1111
common.skip('missing crypto');
1212

13+
const assert = require('assert');
1314
const http2 = require('http2');
1415
const tls = require('tls');
1516
const net = require('net');
@@ -48,6 +49,25 @@ server.on('error', common.mustNotCall());
4849
}));
4950
}
5051

52+
// Test that `http2.createServer()` supports `net.Server` options.
53+
{
54+
const server = http2.createServer({ allowHalfOpen: true });
55+
56+
server.on('connection', common.mustCall((socket) => {
57+
assert.strictEqual(socket.allowHalfOpen, true);
58+
socket.end();
59+
server.close();
60+
}));
61+
62+
assert.strictEqual(server.allowHalfOpen, true);
63+
64+
server.listen(0, common.mustCall(() => {
65+
const port = server.address().port;
66+
const socket = net.connect(port, common.mustCall());
67+
socket.resume();
68+
}));
69+
}
70+
5171
// Test the secure server socket timeout.
5272
{
5373
let client;
@@ -67,3 +87,29 @@ server.on('error', common.mustNotCall());
6787
}, common.mustCall());
6888
}));
6989
}
90+
91+
// Test that `http2.createSecureServer()` supports `net.Server` options.
92+
{
93+
const server = http2.createSecureServer({
94+
allowHalfOpen: true,
95+
...options
96+
});
97+
98+
server.on('secureConnection', common.mustCall((socket) => {
99+
assert.strictEqual(socket.allowHalfOpen, true);
100+
socket.end();
101+
server.close();
102+
}));
103+
104+
assert.strictEqual(server.allowHalfOpen, true);
105+
106+
server.listen(0, common.mustCall(() => {
107+
const port = server.address().port;
108+
const socket = tls.connect({
109+
port: port,
110+
rejectUnauthorized: false,
111+
ALPNProtocols: ['h2']
112+
}, common.mustCall());
113+
socket.resume();
114+
}));
115+
}

0 commit comments

Comments
 (0)