|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const http = require('http'); |
| 6 | + |
| 7 | +var requests = 0; |
| 8 | + |
| 9 | +http.createServer(function(req, res) { |
| 10 | + res.writeHead(200); |
| 11 | + res.end('ok'); |
| 12 | + |
| 13 | + requests++; |
| 14 | +}).listen(common.PORT).unref(); |
| 15 | + |
| 16 | +var agent = new http.Agent(); |
| 17 | +agent.defaultPort = common.PORT; |
| 18 | + |
| 19 | +// options marked as explicitly undefined for readability |
| 20 | +// in this test, they should STAY undefined as options should not |
| 21 | +// be mutable / modified |
| 22 | +var options = { |
| 23 | + host: undefined, |
| 24 | + hostname: common.localhostIPv4, |
| 25 | + port: undefined, |
| 26 | + defaultPort: undefined, |
| 27 | + path: undefined, |
| 28 | + method: undefined, |
| 29 | + agent: agent |
| 30 | +}; |
| 31 | + |
| 32 | +http.request(options, function(res) { |
| 33 | + res.resume(); |
| 34 | +}).end(); |
| 35 | + |
| 36 | +process.on('exit', function() { |
| 37 | + assert.equal(requests, 1); |
| 38 | + |
| 39 | + assert.strictEqual(options.host, undefined); |
| 40 | + assert.strictEqual(options.hostname, common.localhostIPv4); |
| 41 | + assert.strictEqual(options.port, undefined); |
| 42 | + assert.strictEqual(options.defaultPort, undefined); |
| 43 | + assert.strictEqual(options.path, undefined); |
| 44 | + assert.strictEqual(options.method, undefined); |
| 45 | +}); |
0 commit comments