1'use strict'; 2 3// When using the object form of http.request and using an IPv6 address 4// as a hostname, and using a non-standard port, the Host header 5// is improperly formatted. 6// Issue: https://github.com/nodejs/node/issues/5308 7// As per https://tools.ietf.org/html/rfc7230#section-5.4 and 8// https://tools.ietf.org/html/rfc3986#section-3.2.2 9// the IPv6 address should be enclosed in square brackets 10 11const common = require('../common'); 12const assert = require('assert'); 13const http = require('http'); 14const net = require('net'); 15 16const requests = [ 17 { host: 'foo:1234', headers: { expectedhost: 'foo:1234:80' } }, 18 { host: '::1', headers: { expectedhost: '[::1]:80' } }, 19]; 20 21function createLocalConnection(options) { 22 options.host = undefined; 23 options.port = this.port; 24 options.path = undefined; 25 return net.createConnection(options); 26} 27 28http.createServer(common.mustCall(function(req, res) { 29 this.requests = this.requests || 0; 30 assert.strictEqual(req.headers.host, req.headers.expectedhost); 31 res.end(); 32 if (++this.requests === requests.length) 33 this.close(); 34}, requests.length)).listen(0, function() { 35 const address = this.address(); 36 for (let i = 0; i < requests.length; ++i) { 37 requests[i].createConnection = 38 common.mustCall(createLocalConnection.bind(address)); 39 http.get(requests[i]); 40 } 41}); 42