diff options
author | Mihai Potra <mike@mpotra.com> | 2016-02-19 10:21:49 +0200 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-04-01 08:57:16 -0700 |
commit | dabe1d57349caffd3dd1719dac0a4643e24507e2 (patch) | |
tree | 86b31381cdbb4a814210795afa793f3f6909224d /test | |
parent | 5fc6938cff48f978642d7d83e257de36660977d3 (diff) | |
download | android-node-v8-dabe1d57349caffd3dd1719dac0a4643e24507e2.tar.gz android-node-v8-dabe1d57349caffd3dd1719dac0a4643e24507e2.tar.bz2 android-node-v8-dabe1d57349caffd3dd1719dac0a4643e24507e2.zip |
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.
PR-URL: https://github.com/nodejs/node/pull/5314
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-http-host-header-ipv6-fail.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-http-host-header-ipv6-fail.js b/test/parallel/test-http-host-header-ipv6-fail.js new file mode 100644 index 0000000000..8a1a9a61af --- /dev/null +++ b/test/parallel/test-http-host-header-ipv6-fail.js @@ -0,0 +1,40 @@ +'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()); |