Skip to content

Commit 8c35198

Browse files
lpincatargos
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 313077e commit 8c35198

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

doc/api/http2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,10 @@ error will be thrown.
19101910
<!-- YAML
19111911
added: v8.4.0
19121912
changes:
1913+
- version: REPLACEME
1914+
pr-url: https://github.com/nodejs/node/pull/27782
1915+
description: The `options` parameter now supports `net.createServer()`
1916+
options.
19131917
- version: v8.9.3
19141918
pr-url: https://github.com/nodejs/node/pull/17105
19151919
description: Added the `maxOutstandingPings` option with a default limit of
@@ -1985,6 +1989,7 @@ changes:
19851989
`Http2ServerResponse` class to use.
19861990
Useful for extending the original `Http2ServerResponse`.
19871991
**Default:** `Http2ServerResponse`.
1992+
* ...: Any [`net.createServer()`][] option can be provided.
19881993
* `onRequestHandler` {Function} See [Compatibility API][]
19891994
* Returns: {Http2Server}
19901995

@@ -3465,6 +3470,7 @@ following additional properties:
34653470
[`http2.createServer()`]: #http2_http2_createserver_options_onrequesthandler
34663471
[`http2session.close()`]: #http2_http2session_close_callback
34673472
[`http2stream.pushStream()`]: #http2_http2stream_pushstream_headers_options_callback
3473+
[`net.createServer()`]: net.html#net_net_createserver_options_connectionlistener
34683474
[`net.Server.close()`]: net.html#net_server_close_callback
34693475
[`net.Socket.bufferSize`]: net.html#net_socket_buffersize
34703476
[`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
@@ -2701,8 +2701,9 @@ class Http2SecureServer extends TLSServer {
27012701

27022702
class Http2Server extends NETServer {
27032703
constructor(options, requestListener) {
2704-
super(connectionListener);
2705-
this[kOptions] = initializeOptions(options);
2704+
options = initializeOptions(options);
2705+
super(options, connectionListener);
2706+
this[kOptions] = options;
27062707
this.timeout = kDefaultHttpServerTimeout;
27072708
this.on('newListener', setupCompat);
27082709
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)