-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: Corrects IPv6 address in Host header
IPv6 addresses in Host header (URI), must be enclosed within square brackets, in order to properly separate the host address from any port reference. test: add test for IPv6 hostname conformance in Host header http: Ensure IPv6 is enclosed within square brackets in Host header http: use net.isIPv6 in ClientRequest test: update test with const instead of var test: use common.mustCall and cleanup http: ClientRequest, drop isIPv6() in favor of indexOf() checks http: ClientRequest, replace concatenation with string literal test: use const test: clean-up test: move test to parallel test: skip if no IPv6 support
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'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'; | ||
const port = common.PORT; | ||
|
||
function httpreq() { | ||
var req = http.request({ | ||
host: hostname, | ||
port: 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(port, hostname, () => httpreq()); | ||
|