| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 86d7ba0 commit 4202045
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -645,15 +645,21 @@ function initOriginSet(session) { | |||
| 645 | 645 | if (originSet === undefined) { | |
| 646 | 646 | const socket = session[kSocket]; | |
| 647 | 647 | 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 | + } | ||
| 656 | 655 | } | |
| 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)); | ||
| 657 | 663 | } | |
| 658 | 664 | return originSet; | |
| 659 | 665 | } | |
@@ -3342,7 +3348,7 @@ function connect(authority, options, listener) { | |||
| 3342 | 3348 | socket = net.connect({ port, host, ...options }); | |
| 3343 | 3349 | break; | |
| 3344 | 3350 | case 'https:': | |
| 3345 | - socket = tls.connect(port, host, initializeTLSOptions(options, host)); | ||
| 3351 | + socket = tls.connect(port, host, initializeTLSOptions(options, net.isIP(host) ? undefined : host)); | ||
| 3346 | 3352 | break; | |
| 3347 | 3353 | default: | |
| 3348 | 3354 | throw new ERR_HTTP2_UNSUPPORTED_PROTOCOL(protocol); | |
| Original file line number | Diff line number | Diff 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 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments