Skip to content

Commit c43b614

Browse files
committed
http2: set origin name correctly when servername is empty
Fixes: #39919
1 parent 449147e commit c43b614

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/internal/http2/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ function initializeTLSOptions(options, servername) {
30983098
options.ALPNProtocols = ['h2'];
30993099
if (options.allowHTTP1 === true)
31003100
ArrayPrototypePush(options.ALPNProtocols, 'http/1.1');
3101-
if (servername !== undefined && options.servername === undefined)
3101+
if (servername !== undefined && !options.servername)
31023102
options.servername = servername;
31033103
return options;
31043104
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
// Ref: https://github.com/nodejs/node/issues/39919
4+
5+
const common = require('../common');
6+
if (!common.hasCrypto)
7+
common.skip('missing crypto');
8+
9+
const assert = require('assert');
10+
const http2 = require('http2');
11+
12+
function _verifyOriginSet(session, originString) {
13+
session.once('remoteSettings', () => {
14+
assert.strictEqual(typeof session.originSet, 'object');
15+
assert.strictEqual(session.originSet.length, 1);
16+
assert.strictEqual(session.originSet[0], originString);
17+
session.close();
18+
});
19+
session.once('error', (error) => {
20+
assert.strictEqual(error.code, 'ECONNREFUSED');
21+
session.close();
22+
});
23+
}
24+
25+
function withServerName() {
26+
const session = http2.connect('https://1.1.1.1', { servername: 'cloudflare-dns.com' });
27+
_verifyOriginSet(session, 'https://cloudflare-dns.com');
28+
}
29+
30+
function withEmptyServerName() {
31+
const session = http2.connect('https://1.1.1.1', { servername: '' });
32+
_verifyOriginSet(session, 'https://1.1.1.1');
33+
}
34+
35+
function withoutServerName() {
36+
const session = http2.connect('https://1.1.1.1');
37+
_verifyOriginSet(session, 'https://1.1.1.1');
38+
}
39+
40+
withServerName();
41+
withEmptyServerName();
42+
withoutServerName();

0 commit comments

Comments
 (0)