Skip to content

Commit 246a6fc

Browse files
committed
tls: deprecate Server.prototype.setOptions()
This function was undocumented and only used in one place throughout the codebase, plus a test. PR-URL: #23820 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent d8924a0 commit 246a6fc

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

doc/api/deprecations.md

+14
Original file line numberDiff line numberDiff line change
@@ -2279,6 +2279,20 @@ and `cluster` modules on Windows. The function is not generally useful and
22792279
is being removed. See discussion here:
22802280
https://github.com/nodejs/node/issues/18391
22812281
2282+
<a id="DEP0122"></a>
2283+
### DEP0122: tls Server.prototype.setOptions()
2284+
<!-- YAML
2285+
changes:
2286+
- version: REPLACEME
2287+
pr-url: https://github.com/nodejs/node/pull/23820
2288+
description: Runtime deprecation.
2289+
-->
2290+
2291+
Type: Runtime
2292+
2293+
Please use `Server.prototype.setSecureContext()` instead.
2294+
2295+
22822296
[`--pending-deprecation`]: cli.html#cli_pending_deprecation
22832297
[`Buffer.allocUnsafeSlow(size)`]: buffer.html#buffer_class_method_buffer_allocunsafeslow_size
22842298
[`Buffer.from(array)`]: buffer.html#buffer_class_method_buffer_from_array

lib/_tls_wrap.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,19 @@ function Server(options, listener) {
827827
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
828828
}
829829

830-
831830
this._contexts = [];
831+
this.requestCert = options.requestCert === true;
832+
this.rejectUnauthorized = options.rejectUnauthorized !== false;
832833

833-
// Handle option defaults:
834-
this.setOptions(options);
834+
if (options.sessionTimeout)
835+
this.sessionTimeout = options.sessionTimeout;
836+
837+
if (options.ticketKeys)
838+
this.ticketKeys = options.ticketKeys;
839+
840+
if (options.ALPNProtocols)
841+
tls.convertALPNProtocols(options.ALPNProtocols, this);
835842

836-
// setSecureContext() overlaps with setOptions() quite a bit. setOptions()
837-
// is an undocumented API that was probably never intended to be exposed
838-
// publicly. Unfortunately, it would be a breaking change to just remove it,
839-
// and there is at least one test that depends on it.
840843
this.setSecureContext(options);
841844

842845
this[kHandshakeTimeout] = options.handshakeTimeout || (120 * 1000);
@@ -998,7 +1001,7 @@ Server.prototype.setTicketKeys = function setTicketKeys(keys) {
9981001
};
9991002

10001003

1001-
Server.prototype.setOptions = function(options) {
1004+
Server.prototype.setOptions = util.deprecate(function(options) {
10021005
this.requestCert = options.requestCert === true;
10031006
this.rejectUnauthorized = options.rejectUnauthorized !== false;
10041007

@@ -1033,7 +1036,7 @@ Server.prototype.setOptions = function(options) {
10331036
.digest('hex')
10341037
.slice(0, 32);
10351038
}
1036-
};
1039+
}, 'Server.prototype.setOptions() is deprecated', 'DEP0122');
10371040

10381041
// SNI Contexts High-Level API
10391042
Server.prototype.addContext = function(servername, context) {

test/parallel/test-tls-server-setoptions-clientcertengine.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const tls = require('tls');
1010
{
1111
const server = tls.createServer();
1212
assert.strictEqual(server.clientCertEngine, undefined);
13+
common.expectWarning('DeprecationWarning',
14+
'Server.prototype.setOptions() is deprecated',
15+
'DEP0122');
1316
server.setOptions({ clientCertEngine: 'Cannonmouth' });
1417
assert.strictEqual(server.clientCertEngine, 'Cannonmouth');
1518
}

0 commit comments

Comments
 (0)