Skip to content

Commit 6bf85bc

Browse files
test: add test for 06cfff9 regression
This commit adds a test to ensure all options are NOT modified after passing them to http.request. Specifically options.host and options.port are the most prominent that would previously error, but add the other options that have default values. options.host and options.port were overridden for the one-argument net.createConnection(options) call. PR-URL: #1467 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 7180597 commit 6bf85bc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)