upgrade to `agent-base` v2 API
Breaking API change: - User no longer needs to specify `secureEndpoint` when "https" module is being used; 'agent-base' handles this part for us now. - Upgraded "http-proxy-agent", "https-proxy-agent" and "socks-proxy-agent" since they've been updated for the new agent-base API as well.
This commit is contained in:
Родитель
8988843c97
Коммит
f4f8658b8e
8
index.js
8
index.js
|
@ -75,9 +75,6 @@ function PacProxyAgent (uri, opts) {
|
|||
|
||||
Agent.call(this, connect);
|
||||
|
||||
// if `true`, then connect to the destination endpoint over TLS, defaults to `false`
|
||||
this.secureEndpoint = Boolean(opts.secureEndpoint);
|
||||
|
||||
// strip the "pac+" prefix
|
||||
this.uri = uri.replace(/^pac\+/i, '');
|
||||
|
||||
|
@ -181,6 +178,7 @@ function connect (req, opts, fn) {
|
|||
var url;
|
||||
var host;
|
||||
var self = this;
|
||||
var secure = Boolean(opts.secureEndpoint);
|
||||
|
||||
// first we need get a generated FindProxyForURL() function,
|
||||
// either cached or retreived from the source
|
||||
|
@ -191,7 +189,6 @@ function connect (req, opts, fn) {
|
|||
if (err) return fn(err);
|
||||
|
||||
// calculate the `url` parameter
|
||||
var secure = self.secureEndpoint;
|
||||
var defaultPort = secure ? 443 : 80;
|
||||
var path = req.path;
|
||||
var firstQuestion = path.indexOf('?');
|
||||
|
@ -236,7 +233,6 @@ function connect (req, opts, fn) {
|
|||
var agent;
|
||||
var parts = first.split(/\s+/);
|
||||
var type = parts[0];
|
||||
var secure = self.secureEndpoint;
|
||||
|
||||
if ('DIRECT' == type) {
|
||||
// direct connection to the destination endpoint
|
||||
|
@ -249,7 +245,7 @@ function connect (req, opts, fn) {
|
|||
return fn(null, socket);
|
||||
} else if ('SOCKS' == type) {
|
||||
// use a SOCKS proxy
|
||||
agent = new SocksProxyAgent('socks://' + parts[1], secure);
|
||||
agent = new SocksProxyAgent('socks://' + parts[1]);
|
||||
} else if ('PROXY' == type || 'HTTPS' == type) {
|
||||
// use an HTTP or HTTPS proxy
|
||||
// http://dev.chromium.org/developers/design-documents/secure-web-proxy
|
||||
|
|
10
package.json
10
package.json
|
@ -27,15 +27,15 @@
|
|||
},
|
||||
"homepage": "https://github.com/TooTallNate/node-pac-proxy-agent",
|
||||
"dependencies": {
|
||||
"agent-base": "~1.0.1",
|
||||
"agent-base": "2",
|
||||
"debug": "2",
|
||||
"extend": "3",
|
||||
"get-uri": "1",
|
||||
"http-proxy-agent": "^0.2.6",
|
||||
"https-proxy-agent": "^0.3.5",
|
||||
"http-proxy-agent": "1",
|
||||
"https-proxy-agent": "1",
|
||||
"pac-resolver": "~1.2.1",
|
||||
"socks-proxy-agent": "^1.0.2",
|
||||
"stream-to-buffer": "^0.1.0"
|
||||
"socks-proxy-agent": "2",
|
||||
"stream-to-buffer": "0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "2",
|
||||
|
|
30
test/test.js
30
test/test.js
|
@ -115,40 +115,15 @@ describe('PacProxyAgent', function () {
|
|||
it('should accept a "string" proxy argument', function () {
|
||||
var agent = new PacProxyAgent('pac+ftp://example.com/proxy.pac');
|
||||
assert.equal('ftp://example.com/proxy.pac', agent.uri);
|
||||
assert.equal(false, agent.secureEndpoint);
|
||||
});
|
||||
it('should accept a `url.parse()` result object argument', function () {
|
||||
var opts = url.parse('pac+ftp://example.com/proxy.pac');
|
||||
var agent = new PacProxyAgent(opts);
|
||||
assert.equal('ftp://example.com/proxy.pac', agent.uri);
|
||||
assert.equal(false, agent.secureEndpoint);
|
||||
});
|
||||
it('should accept a `uri` on the options object', function () {
|
||||
var agent = new PacProxyAgent({ uri: 'pac+ftp://example.com/proxy.pac' });
|
||||
assert.equal('ftp://example.com/proxy.pac', agent.uri);
|
||||
assert.equal(false, agent.secureEndpoint);
|
||||
});
|
||||
describe('secureEndpoint', function () {
|
||||
it('should default to `false`', function () {
|
||||
var opts = url.parse('ftp://example.com/proxy.pac');
|
||||
var agent = new PacProxyAgent(opts);
|
||||
assert.equal('ftp://example.com/proxy.pac', agent.uri);
|
||||
assert.equal(false, agent.secureEndpoint);
|
||||
});
|
||||
it('should be `true` when passed in as a parse() option', function () {
|
||||
var opts = url.parse('ftp://example.com/proxy.pac');
|
||||
opts.secureEndpoint = true;
|
||||
var agent = new PacProxyAgent(opts);
|
||||
assert.equal('ftp://example.com/proxy.pac', agent.uri);
|
||||
assert.equal(true, agent.secureEndpoint);
|
||||
});
|
||||
it('should be `true` when passed in as an option', function () {
|
||||
var agent = new PacProxyAgent('ftp://example.com/proxy.pac', {
|
||||
secureEndpoint: true
|
||||
});
|
||||
assert.equal('ftp://example.com/proxy.pac', agent.uri);
|
||||
assert.equal(true, agent.secureEndpoint);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -249,7 +224,7 @@ describe('PacProxyAgent', function () {
|
|||
}
|
||||
|
||||
var uri = 'data:,' + encodeURIComponent(FindProxyForURL.toString().replace('PORT', proxyPort));
|
||||
var agent = new PacProxyAgent(uri, { secureEndpoint: true });
|
||||
var agent = new PacProxyAgent(uri);
|
||||
|
||||
var opts = url.parse('https://127.0.0.1:' + httpsPort + '/test');
|
||||
opts.agent = agent;
|
||||
|
@ -279,7 +254,6 @@ describe('PacProxyAgent', function () {
|
|||
|
||||
var uri = 'data:,' + encodeURIComponent(FindProxyForURL.toString().replace('PORT', proxyHttpsPort));
|
||||
var agent = new PacProxyAgent(uri, {
|
||||
secureEndpoint: true,
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
|
@ -311,7 +285,7 @@ describe('PacProxyAgent', function () {
|
|||
}
|
||||
|
||||
var uri = 'data:,' + encodeURIComponent(FindProxyForURL.toString().replace('PORT', socksPort));
|
||||
var agent = new PacProxyAgent(uri, { secureEndpoint: true });
|
||||
var agent = new PacProxyAgent(uri);
|
||||
|
||||
var opts = url.parse('https://127.0.0.1:' + httpsPort + '/test');
|
||||
opts.agent = agent;
|
||||
|
|
Загрузка…
Ссылка в новой задаче