Skip to content

Commit fe77de1

Browse files
dirceubnoordhuis
authored andcommitted
http: use localAddress instead of path
Fix `options` usage on `lib/_http_agent.js` for the Legacy API. Fixes: #5051 PR-URL: #5190 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Brian White <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b90c52e commit fe77de1

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/_http_agent.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ Agent.prototype.getName = function(options) {
106106
};
107107

108108
Agent.prototype.addRequest = function(req, options) {
109-
// Legacy API: addRequest(req, host, port, path)
109+
// Legacy API: addRequest(req, host, port, localAddress)
110110
if (typeof options === 'string') {
111111
options = {
112112
host: options,
113113
port: arguments[2],
114-
path: arguments[3]
114+
localAddress: arguments[3]
115115
};
116116
}
117117

test/parallel/test-regress-GH-5051.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const agent = require('http').globalAgent;
5+
6+
// small stub just so we can call addRequest directly
7+
const req = {
8+
getHeader: function() {}
9+
};
10+
11+
agent.maxSockets = 0;
12+
13+
// localAddress is used when naming requests / sockets
14+
// while using the Legacy API
15+
agent.addRequest(req, 'localhost', common.PORT, '127.0.0.1');
16+
assert.equal(Object.keys(agent.requests).length, 1);
17+
assert.equal(
18+
Object.keys(agent.requests)[0],
19+
'localhost:' + common.PORT + ':127.0.0.1');
20+
21+
// path is *not* used when naming requests / sockets
22+
agent.addRequest(req, {
23+
host: 'localhost',
24+
port: common.PORT,
25+
localAddress: '127.0.0.1',
26+
path: '/foo'
27+
});
28+
assert.equal(Object.keys(agent.requests).length, 1);
29+
assert.equal(
30+
Object.keys(agent.requests)[0],
31+
'localhost:' + common.PORT + ':127.0.0.1');

0 commit comments

Comments
 (0)