Skip to content

Commit fae3109

Browse files
committed
tls: support net.Server options
Pass `tls.Server` constructor options to the parent constructor.
1 parent 3309c85 commit fae3109

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

doc/api/tls.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,10 @@ publicly trusted list of CAs as given in
14361436
<!-- YAML
14371437
added: v0.3.2
14381438
changes:
1439+
- version: REPLACEME
1440+
pr-url: https://github.com/nodejs/node/pull/27665
1441+
description: The `options` parameter now supports `net.createServer()`
1442+
options.
14391443
- version: v9.3.0
14401444
pr-url: https://github.com/nodejs/node/pull/14903
14411445
description: The `options` parameter can now include `clientCertEngine`.
@@ -1486,6 +1490,7 @@ changes:
14861490
data. See [Session Resumption][] for more information.
14871491
* ...: Any [`tls.createSecureContext()`][] option can be provided. For
14881492
servers, the identity options (`pfx` or `key`/`cert`) are usually required.
1493+
* ...: Any [`net.createServer()`][] option can be provided.
14891494
* `secureConnectionListener` {Function}
14901495
* Returns: {tls.Server}
14911496

@@ -1706,6 +1711,7 @@ where `secureSocket` has the same API as `pair.cleartext`.
17061711
[`NODE_OPTIONS`]: cli.html#cli_node_options_options
17071712
[`crypto.getCurves()`]: crypto.html#crypto_crypto_getcurves
17081713
[`dns.lookup()`]: dns.html#dns_dns_lookup_hostname_options_callback
1714+
[`net.createServer()`]: net.html#net_net_createserver_options_connectionlistener
17091715
[`net.Server.address()`]: net.html#net_server_address
17101716
[`net.Server`]: net.html#net_class_net_server
17111717
[`net.Socket`]: net.html#net_class_net_socket

lib/_tls_wrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ function Server(options, listener) {
10101010
}
10111011

10121012
// constructor call
1013-
net.Server.call(this, tlsConnectionListener);
1013+
net.Server.call(this, options, tlsConnectionListener);
10141014

10151015
if (listener) {
10161016
this.on('secureConnection', listener);
Lines changed: 63 additions & 0 deletions
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)