Skip to content

Commit f0de101

Browse files
http: fix agent.getName() and add tests
This commit fixes agent.getName(), which returned an extra colon according to the docs, and adds tests (it was previously not unit tested).
1 parent 115bf08 commit f0de101

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

lib/_http_agent.js

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ Agent.prototype.getName = function(options) {
107107
name += ':';
108108
if (options.localAddress)
109109
name += options.localAddress;
110-
name += ':';
111110
return name;
112111
};
113112

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
var http = require('http');
5+
var common = require('../common');
6+
7+
var agent = new http.Agent();
8+
9+
// default to localhost
10+
assert.equal(
11+
agent.getName({
12+
port: 80,
13+
localAddress: '192.168.1.1'
14+
}),
15+
'localhost:80:192.168.1.1'
16+
);
17+
18+
// empty
19+
assert.equal(
20+
agent.getName({}),
21+
'localhost::'
22+
);
23+
24+
// pass all arguments
25+
assert.equal(
26+
agent.getName({
27+
host: '0.0.0.0',
28+
port: 80,
29+
localAddress: '192.168.1.1'
30+
}),
31+
'0.0.0.0:80:192.168.1.1'
32+
);

test/parallel/test-http-agent-keepalive.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function get(path, callback) {
3535
}, callback);
3636
}
3737

38-
var name = 'localhost:' + common.PORT + '::';
38+
var name = 'localhost:' + common.PORT + ':';
3939

4040
function checkDataAndSockets(body) {
4141
assert.equal(body.toString(), 'hello world');

0 commit comments

Comments
 (0)