GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: omit server name when HTTP2 host is IP address · nodejs/node@4c24ef8

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/http2
    • core.js
  • test/parallel
    • test-http2-ip-address-host.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+15-9Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,21 @@ function initOriginSet(session) {
645645
if (originSet === undefined) {
646646
const socket = session[kSocket];
647647
session[kState].originSet = originSet = new SafeSet();
648-
if (socket.servername != null) {
649-
let originString = `https://${socket.servername}`;
650-
if (socket.remotePort != null)
651-
originString += `:${socket.remotePort}`;
652-
// We have to ensure that it is a properly serialized
653-
// ASCII origin string. The socket.servername might not
654-
// be properly ASCII encoded.
655-
originSet.add(getURLOrigin(originString));
648+
let hostName = socket.servername;
649+
if (hostName === null || hostName === false) {
650+
if (socket.remoteFamily === 'IPv6') {
651+
hostName = `[${socket.remoteAddress}]`;
652+
} else {
653+
hostName = socket.remoteAddress;
654+
}
656655
}
656+
let originString = `https://${hostName}`;
657+
if (socket.remotePort != null)
658+
originString += `:${socket.remotePort}`;
659+
// We have to ensure that it is a properly serialized
660+
// ASCII origin string. The socket.servername might not
661+
// be properly ASCII encoded.
662+
originSet.add(getURLOrigin(originString));
657663
}
658664
return originSet;
659665
}
@@ -3352,7 +3358,7 @@ function connect(authority, options, listener) {
33523358
socket = net.connect({ port, host, ...options });
33533359
break;
33543360
case 'https:':
3355-
socket = tls.connect(port, host, initializeTLSOptions(options, host));
3361+
socket = tls.connect(port, host, initializeTLSOptions(options, net.isIP(host) ? undefined : host));
33563362
break;
33573363
default:
33583364
throw new ERR_HTTP2_UNSUPPORTED_PROTOCOL(protocol);
Collapse file

‎test/parallel/test-http2-ip-address-host.js‎

Copy file name to clipboard
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto) { common.skip('missing crypto'); }
5+
const assert = require('assert');
6+
const fixtures = require('../common/fixtures');
7+
const h2 = require('http2');
8+
9+
function loadKey(keyname) {
10+
return fixtures.readKey(keyname, 'binary');
11+
}
12+
13+
const key = loadKey('agent8-key.pem');
14+
const cert = fixtures.readKey('agent8-cert.pem');
15+
16+
const server = h2.createSecureServer({ key, cert });
17+
const hasIPv6 = common.hasIPv6;
18+
const testCount = hasIPv6 ? 2 : 1;
19+
20+
server.on('stream', common.mustCall((stream) => {
21+
const session = stream.session;
22+
assert.strictEqual(session.servername, undefined);
23+
stream.respond({ 'content-type': 'application/json' });
24+
stream.end(JSON.stringify({
25+
servername: session.servername,
26+
originSet: session.originSet
27+
})
28+
);
29+
}, testCount));
30+
31+
let done = 0;
32+
33+
server.listen(0, common.mustCall(() => {
34+
function handleRequest(url) {
35+
const client = h2.connect(url,
36+
{ rejectUnauthorized: false });
37+
const req = client.request();
38+
let data = '';
39+
req.setEncoding('utf8');
40+
req.on('data', (d) => data += d);
41+
req.on('end', common.mustCall(() => {
42+
const originSet = req.session.originSet;
43+
assert.strictEqual(originSet[0], url);
44+
client.close();
45+
if (++done === testCount) server.close();
46+
}));
47+
}
48+
49+
const ipv4Url = `https://127.0.0.1:${server.address().port}`;
50+
const ipv6Url = `https://[::1]:${server.address().port}`;
51+
handleRequest(ipv4Url);
52+
if (hasIPv6) handleRequest(ipv6Url);
53+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.