mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 21:04:16 +00:00

This helps to prevent issues where a failed test can keep a bound socket open long enough to cause other tests to fail with EADDRINUSE because the same port number is used. PR-URL: https://github.com/nodejs/node/pull/7045 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
40 lines
987 B
JavaScript
40 lines
987 B
JavaScript
'use strict';
|
|
/*
|
|
* When using the object form of http.request and using an IPv6 address
|
|
* as a hostname, and using a non-standard port, the Host header
|
|
* is improperly formatted.
|
|
* Issue: https://github.com/nodejs/node/issues/5308
|
|
* As per https://tools.ietf.org/html/rfc7230#section-5.4 and
|
|
* https://tools.ietf.org/html/rfc3986#section-3.2.2
|
|
* the IPv6 address should be enclosed in square brackets
|
|
*/
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const hostname = '::1';
|
|
|
|
function httpreq() {
|
|
var req = http.request({
|
|
host: hostname,
|
|
port: server.address().port,
|
|
path: '/',
|
|
method: 'GET'
|
|
});
|
|
req.end();
|
|
}
|
|
|
|
if (!common.hasIPv6) {
|
|
console.error('Skipping test, no IPv6 support');
|
|
return;
|
|
}
|
|
|
|
const server = http.createServer(common.mustCall(function(req, res) {
|
|
assert.ok(req.headers.host, `[${hostname}]`);
|
|
res.end();
|
|
server.close(true);
|
|
}));
|
|
|
|
server.listen(0, hostname, () => httpreq());
|