Skip to content

Commit 1c7778d

Browse files
http: revert 06cfff9, fixes overridden options
This commit reverts commit 06cfff9 and adds a test that failed before the revert. Options is in fact overridden in the code below the util._extend() call (specifically options.port and options.host) to allow for a one-argument net.createConnection(options) call.
1 parent e61ee49 commit 1c7778d

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

lib/_http_client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function ClientRequest(options, cb) {
2121

2222
if (typeof options === 'string') {
2323
options = url.parse(options);
24+
} else {
25+
options = util._extend({}, options);
2426
}
2527

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

0 commit comments

Comments
 (0)