Skip to content

Commit 84a1210

Browse files
jan-auerTooTallNate
authored andcommitted
Add defaultPort field (#43)
* Add defaultPort to the Agent * Add tests for defaultPort
1 parent b9d5b7e commit 84a1210

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function HttpsProxyAgent(opts) {
5656
}
5757

5858
this.proxy = proxy;
59+
this.defaultPort = 443;
5960
}
6061
inherits(HttpsProxyAgent, Agent);
6162

test/test.js

+34
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ describe('HttpsProxyAgent', function () {
107107
assert.equal('127.0.0.1', agent.proxy.host);
108108
assert.equal(proxyPort, agent.proxy.port);
109109
});
110+
it('should set a `defaultPort` property', function () {
111+
var opts = url.parse("http://127.0.0.1:" + proxyPort);
112+
var agent = new HttpsProxyAgent(opts);
113+
assert.equal(443, agent.defaultPort);
114+
});
110115
describe('secureProxy', function () {
111116
it('should default to `false`', function () {
112117
var agent = new HttpsProxyAgent({ port: proxyPort });
@@ -303,6 +308,35 @@ describe('HttpsProxyAgent', function () {
303308
});
304309
});
305310

311+
it('should not send a port number for the default port', function (done) {
312+
sslServer.once('request', function (req, res) {
313+
res.end(JSON.stringify(req.headers));
314+
});
315+
316+
var proxy = process.env.HTTPS_PROXY || process.env.https_proxy || "https://127.0.0.1:" + sslProxyPort;
317+
proxy = url.parse(proxy);
318+
proxy.rejectUnauthorized = false;
319+
var agent = new HttpsProxyAgent(proxy);
320+
agent.defaultPort = sslServerPort;
321+
322+
var opts = url.parse("https://127.0.0.1:" + sslServerPort);
323+
opts.agent = agent;
324+
opts.rejectUnauthorized = false;
325+
326+
https.get(opts, function(res) {
327+
var data = "";
328+
res.setEncoding("utf8");
329+
res.on("data", function(b) {
330+
data += b;
331+
});
332+
res.on("end", function() {
333+
data = JSON.parse(data);
334+
assert.equal("127.0.0.1", data.host);
335+
done();
336+
});
337+
});
338+
});
339+
306340
});
307341

308342
});

0 commit comments

Comments
 (0)