|
12 | 12 | const common = require('../common');
|
13 | 13 | const assert = require('assert');
|
14 | 14 | const http = require('http');
|
| 15 | +const net = require('net'); |
15 | 16 |
|
16 |
| -const hostname = '::1'; |
| 17 | +const requests = [ |
| 18 | + { host: 'foo:1234', headers: { expectedhost: 'foo:1234:80' } }, |
| 19 | + { host: '::1', headers: { expectedhost: '[::1]:80' } } |
| 20 | +]; |
17 | 21 |
|
18 |
| -function httpreq() { |
19 |
| - const req = http.request({ |
20 |
| - host: hostname, |
21 |
| - port: server.address().port, |
22 |
| - path: '/', |
23 |
| - method: 'GET' |
24 |
| - }); |
25 |
| - req.end(); |
| 22 | +function createLocalConnection(options) { |
| 23 | + options.host = undefined; |
| 24 | + options.port = this.port; |
| 25 | + options.path = undefined; |
| 26 | + return net.createConnection(options); |
26 | 27 | }
|
27 | 28 |
|
28 |
| -if (!common.hasIPv6) { |
29 |
| - console.error('Skipping test, no IPv6 support'); |
30 |
| - return; |
31 |
| -} |
32 |
| - |
33 |
| -const server = http.createServer(common.mustCall(function(req, res) { |
34 |
| - assert.ok(req.headers.host, `[${hostname}]`); |
| 29 | +http.createServer(common.mustCall(function(req, res) { |
| 30 | + this.requests = this.requests || 0; |
| 31 | + assert.strictEqual(req.headers.host, req.headers.expectedhost); |
35 | 32 | res.end();
|
36 |
| - server.close(true); |
37 |
| -})); |
38 |
| - |
39 |
| -server.listen(0, hostname, () => httpreq()); |
| 33 | + if (++this.requests === requests.length) |
| 34 | + this.close(); |
| 35 | +}, requests.length)).listen(0, function() { |
| 36 | + const address = this.address(); |
| 37 | + for (let i = 0; i < requests.length; ++i) { |
| 38 | + requests[i].createConnection = |
| 39 | + common.mustCall(createLocalConnection.bind(address)); |
| 40 | + http.get(requests[i]); |
| 41 | + } |
| 42 | +}); |
0 commit comments