Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ const { validateObject } = require('internal/validators');
function Server(opts, requestListener) {
if (!(this instanceof Server)) return new Server(opts, requestListener);

let ALPNProtocols = ['http/1.1'];
if (typeof opts === 'function') {
requestListener = opts;
opts = kEmptyObject;
} else if (opts == null) {
opts = kEmptyObject;
} else {
validateObject(opts, 'options');
// Only one of ALPNProtocols and ALPNCallback can be set, so make sure we
// only set a default ALPNProtocols if the caller has not set either of them
if (opts.ALPNProtocols || opts.ALPNCallback)
ALPNProtocols = undefined;
}

FunctionPrototypeCall(storeHTTPOptions, this, opts);
FunctionPrototypeCall(tls.Server, this,
{
noDelay: true,
// http/1.0 is not defined as Protocol IDs in IANA
// https://www.iana.org/assignments/tls-extensiontype-values
// /tls-extensiontype-values.xhtml#alpn-protocol-ids
ALPNProtocols: ['http/1.1'],
ALPNProtocols,
...opts,
},
_connectionListener);
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-https-argument-of-creating.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ const dftProtocol = {};
0);
assert.strictEqual(server.listeners('request').length, 0);
}


// Validate that `createServer` only uses defaults when appropriate
{
const ALPNCallback = () => {};
const server = https.createServer({
ALPNCallback,
});
assert.strictEqual(server.ALPNProtocols, undefined);
assert.strictEqual(server.ALPNCallback, ALPNCallback);
}