Skip to content

Commit 41f5eac

Browse files
mscdextargos
authored andcommitted
https: only use default ALPNProtocols when appropriate
PR-URL: #54411 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 4d361b3 commit 41f5eac

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/https.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,25 @@ const { validateObject } = require('internal/validators');
6262
function Server(opts, requestListener) {
6363
if (!(this instanceof Server)) return new Server(opts, requestListener);
6464

65+
let ALPNProtocols = ['http/1.1'];
6566
if (typeof opts === 'function') {
6667
requestListener = opts;
6768
opts = kEmptyObject;
6869
} else if (opts == null) {
6970
opts = kEmptyObject;
7071
} else {
7172
validateObject(opts, 'options');
73+
// Only one of ALPNProtocols and ALPNCallback can be set, so make sure we
74+
// only set a default ALPNProtocols if the caller has not set either of them
75+
if (opts.ALPNProtocols || opts.ALPNCallback)
76+
ALPNProtocols = undefined;
7277
}
7378

7479
FunctionPrototypeCall(storeHTTPOptions, this, opts);
7580
FunctionPrototypeCall(tls.Server, this,
7681
{
7782
noDelay: true,
78-
// http/1.0 is not defined as Protocol IDs in IANA
79-
// https://www.iana.org/assignments/tls-extensiontype-values
80-
// /tls-extensiontype-values.xhtml#alpn-protocol-ids
81-
ALPNProtocols: ['http/1.1'],
83+
ALPNProtocols,
8284
...opts,
8385
},
8486
_connectionListener);

test/parallel/test-https-argument-of-creating.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,14 @@ const dftProtocol = {};
4545
0);
4646
assert.strictEqual(server.listeners('request').length, 0);
4747
}
48+
49+
50+
// Validate that `createServer` only uses defaults when appropriate
51+
{
52+
const ALPNCallback = () => {};
53+
const server = https.createServer({
54+
ALPNCallback,
55+
});
56+
assert.strictEqual(server.ALPNProtocols, undefined);
57+
assert.strictEqual(server.ALPNCallback, ALPNCallback);
58+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy