Skip to content

Commit e61823c

Browse files
lpincatargos
authored andcommitted
tls: support net.Server options
Pass `tls.Server` constructor options to the parent constructor. PR-URL: #27665 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent c3d1675 commit e61823c

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

doc/api/tls.md

+6
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,10 @@ publicly trusted list of CAs as given in
14851485
<!-- YAML
14861486
added: v0.3.2
14871487
changes:
1488+
- version: REPLACEME
1489+
pr-url: https://github.com/nodejs/node/pull/27665
1490+
description: The `options` parameter now supports `net.createServer()`
1491+
options.
14881492
- version: v9.3.0
14891493
pr-url: https://github.com/nodejs/node/pull/14903
14901494
description: The `options` parameter can now include `clientCertEngine`.
@@ -1535,6 +1539,7 @@ changes:
15351539
data. See [Session Resumption][] for more information.
15361540
* ...: Any [`tls.createSecureContext()`][] option can be provided. For
15371541
servers, the identity options (`pfx` or `key`/`cert`) are usually required.
1542+
* ...: Any [`net.createServer()`][] option can be provided.
15381543
* `secureConnectionListener` {Function}
15391544
* Returns: {tls.Server}
15401545

@@ -1755,6 +1760,7 @@ where `secureSocket` has the same API as `pair.cleartext`.
17551760
[`NODE_OPTIONS`]: cli.html#cli_node_options_options
17561761
[`crypto.getCurves()`]: crypto.html#crypto_crypto_getcurves
17571762
[`dns.lookup()`]: dns.html#dns_dns_lookup_hostname_options_callback
1763+
[`net.createServer()`]: net.html#net_net_createserver_options_connectionlistener
17581764
[`net.Server.address()`]: net.html#net_server_address
17591765
[`net.Server`]: net.html#net_class_net_server
17601766
[`net.Socket`]: net.html#net_class_net_socket

lib/_tls_wrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ function Server(options, listener) {
10401040
}
10411041

10421042
// constructor call
1043-
net.Server.call(this, tlsConnectionListener);
1043+
net.Server.call(this, options, tlsConnectionListener);
10441044

10451045
if (listener) {
10461046
this.on('secureConnection', listener);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
// Test that `tls.Server` constructor options are passed to the parent
8+
// constructor.
9+
10+
const assert = require('assert');
11+
const fixtures = require('../common/fixtures');
12+
const tls = require('tls');
13+
14+
const options = {
15+
key: fixtures.readKey('agent1-key.pem'),
16+
cert: fixtures.readKey('agent1-cert.pem'),
17+
};
18+
19+
{
20+
const server = tls.createServer(options, common.mustCall((socket) => {
21+
assert.strictEqual(socket.allowHalfOpen, false);
22+
}));
23+
24+
assert.strictEqual(server.allowHalfOpen, false);
25+
26+
server.listen(0, common.mustCall(() => {
27+
const socket = tls.connect({
28+
port: server.address().port,
29+
rejectUnauthorized: false
30+
}, common.mustCall(() => {
31+
socket.end();
32+
}));
33+
34+
socket.on('close', () => {
35+
server.close();
36+
});
37+
}));
38+
}
39+
40+
{
41+
const server = tls.createServer({
42+
allowHalfOpen: true,
43+
...options
44+
}, common.mustCall((socket) => {
45+
assert.strictEqual(socket.allowHalfOpen, true);
46+
socket.on('end', socket.end);
47+
}));
48+
49+
assert.strictEqual(server.allowHalfOpen, true);
50+
51+
server.listen(0, common.mustCall(() => {
52+
const socket = tls.connect({
53+
port: server.address().port,
54+
rejectUnauthorized: false
55+
}, common.mustCall(() => {
56+
socket.end();
57+
}));
58+
59+
socket.on('close', () => {
60+
server.close();
61+
});
62+
}));
63+
}

0 commit comments

Comments
 (0)