Skip to content

Commit 60db96c

Browse files
committed
fixup! use kEmptyObject for options and apply same change to https.server
1 parent 882d62d commit 60db96c

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

lib/_http_server.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ const {
7878
ERR_INVALID_ARG_VALUE,
7979
ERR_INVALID_CHAR
8080
} = codes;
81+
const {
82+
kEmptyObject,
83+
} = require('internal/util');
8184
const {
8285
validateInteger,
8386
validateBoolean,
@@ -432,9 +435,6 @@ function storeHTTPOptions(options) {
432435
validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
433436
this.insecureHTTPParser = insecureHTTPParser;
434437

435-
if (options.noDelay === undefined)
436-
options.noDelay = true;
437-
438438
const requestTimeout = options.requestTimeout;
439439
if (requestTimeout !== undefined) {
440440
validateInteger(requestTimeout, 'requestTimeout', 0);
@@ -501,17 +501,17 @@ function Server(options, requestListener) {
501501

502502
if (typeof options === 'function') {
503503
requestListener = options;
504-
options = {};
504+
options = kEmptyObject;
505505
} else if (options == null) {
506-
options = {};
506+
options = kEmptyObject;
507507
} else {
508508
validateObject(options, 'options');
509509
}
510510

511511
storeHTTPOptions.call(this, options);
512512
net.Server.call(
513513
this,
514-
{ allowHalfOpen: true, noDelay: options.noDelay,
514+
{ allowHalfOpen: true, noDelay: options.noDelay || true,
515515
keepAlive: options.keepAlive,
516516
keepAliveInitialDelay: options.keepAliveInitialDelay });
517517

lib/https.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,28 @@ let debug = require('internal/util/debuglog').debuglog('https', (fn) => {
5353
debug = fn;
5454
});
5555
const { URL, urlToHttpOptions, searchParamsSymbol } = require('internal/url');
56+
const { validateObject } = require('internal/validators');
5657

5758
function Server(opts, requestListener) {
5859
if (!(this instanceof Server)) return new Server(opts, requestListener);
5960

6061
if (typeof opts === 'function') {
6162
requestListener = opts;
62-
opts = undefined;
63-
}
64-
opts = { ...opts };
65-
66-
if (!opts.ALPNProtocols) {
67-
// http/1.0 is not defined as Protocol IDs in IANA
68-
// https://www.iana.org/assignments/tls-extensiontype-values
69-
// /tls-extensiontype-values.xhtml#alpn-protocol-ids
70-
opts.ALPNProtocols = ['http/1.1'];
63+
opts = kEmptyObject;
64+
} else if (opts == null) {
65+
opts = kEmptyObject;
66+
} else {
67+
validateObject(opts, 'options');
7168
}
7269

7370
FunctionPrototypeCall(storeHTTPOptions, this, opts);
74-
FunctionPrototypeCall(tls.Server, this, opts, _connectionListener);
71+
FunctionPrototypeCall(tls.Server, this,
72+
{ ...opts,
73+
// http/1.0 is not defined as Protocol IDs in IANA
74+
// https://www.iana.org/assignments/tls-extensiontype-values
75+
// /tls-extensiontype-values.xhtml#alpn-protocol-ids
76+
ALPNProtocols: opts.ALPNProtocols || ['http/1.1'] },
77+
_connectionListener);
7578

7679
this.httpAllowHalfOpen = false;
7780

test/parallel/test-https-simple.js

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ const serverCallback = common.mustCall(function(req, res) {
4444
res.end(body);
4545
});
4646

47+
const invalid_options = [ 'foo', 42, true, [] ];
48+
invalid_options.forEach((option) => {
49+
assert.throws(() => {
50+
new https.Server(option);
51+
}, {
52+
code: 'ERR_INVALID_ARG_TYPE',
53+
});
54+
});
55+
4756
const server = https.createServer(options, serverCallback);
4857

4958
server.listen(0, common.mustCall(() => {

0 commit comments

Comments
 (0)