Skip to content

Commit

Permalink
Add defaultPort field (#43)
Browse files Browse the repository at this point in the history
* Add defaultPort to the Agent

* Add tests for defaultPort
  • Loading branch information
jan-auer authored and TooTallNate committed Mar 29, 2018
1 parent b9d5b7e commit 84a1210
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -56,6 +56,7 @@ function HttpsProxyAgent(opts) {
}

this.proxy = proxy;
this.defaultPort = 443;
}
inherits(HttpsProxyAgent, Agent);

Expand Down
34 changes: 34 additions & 0 deletions test/test.js
Expand Up @@ -107,6 +107,11 @@ describe('HttpsProxyAgent', function () {
assert.equal('127.0.0.1', agent.proxy.host);
assert.equal(proxyPort, agent.proxy.port);
});
it('should set a `defaultPort` property', function () {
var opts = url.parse("http://127.0.0.1:" + proxyPort);
var agent = new HttpsProxyAgent(opts);
assert.equal(443, agent.defaultPort);
});
describe('secureProxy', function () {
it('should default to `false`', function () {
var agent = new HttpsProxyAgent({ port: proxyPort });
Expand Down Expand Up @@ -303,6 +308,35 @@ describe('HttpsProxyAgent', function () {
});
});

it('should not send a port number for the default port', function (done) {
sslServer.once('request', function (req, res) {
res.end(JSON.stringify(req.headers));
});

var proxy = process.env.HTTPS_PROXY || process.env.https_proxy || "https://127.0.0.1:" + sslProxyPort;
proxy = url.parse(proxy);
proxy.rejectUnauthorized = false;
var agent = new HttpsProxyAgent(proxy);
agent.defaultPort = sslServerPort;

var opts = url.parse("https://127.0.0.1:" + sslServerPort);
opts.agent = agent;
opts.rejectUnauthorized = false;

https.get(opts, function(res) {
var data = "";
res.setEncoding("utf8");
res.on("data", function(b) {
data += b;
});
res.on("end", function() {
data = JSON.parse(data);
assert.equal("127.0.0.1", data.host);
done();
});
});
});

});

});

0 comments on commit 84a1210

Please sign in to comment.