-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http2: omit server name when HTTP2 host is IP address #56530
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) { common.skip('missing crypto'); }; | ||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
const h2 = require('http2'); | ||
|
||
function loadKey(keyname) { | ||
return fixtures.readKey(keyname, 'binary'); | ||
} | ||
|
||
const key = loadKey('agent8-key.pem'); | ||
const cert = fixtures.readKey('agent8-cert.pem'); | ||
|
||
const server = h2.createSecureServer({ key, cert }); | ||
server.on('stream', common.mustCall((stream) => { | ||
const session = stream.session; | ||
assert.strictEqual(session.servername, undefined); | ||
stream.respond({ 'content-type': 'application/json' }); | ||
stream.end(JSON.stringify({ | ||
servername: session.servername, | ||
originSet: session.originSet | ||
}) | ||
); | ||
}, 2)); | ||
|
||
let done = 0; | ||
|
||
server.listen(0, common.mustCall(() => { | ||
function handleRequest(url) { | ||
const client = h2.connect(url, | ||
{ rejectUnauthorized: false }); | ||
const req = client.request(); | ||
let data = ''; | ||
req.setEncoding('utf8'); | ||
req.on('data', (d) => data += d); | ||
req.on('end', common.mustCall(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't the requests be done in parallel? Then server can be closed with something in the listeners of if (++done === 2) server.close(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've made some adjustments to process the requests in parallel. |
||
const originSet = req.session.originSet; | ||
assert.strictEqual(originSet[0], url); | ||
client.close(); | ||
if (++done === 2) server.close(); | ||
})); | ||
} | ||
|
||
const ipv4Url = `https://127.0.0.1:${server.address().port}`; | ||
const ipv6Url = `https://[::1]:${server.address().port}`; | ||
handleRequest(ipv4Url); | ||
if (common.hasIPv6) handleRequest(ipv6Url); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this branch because the EADDRNOTAVAIL error was occurring in the tests. |
||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to RFC 8336, when the server name is not set, the server's address should be used instead.