mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 12:00:14 +02:00
Replace caw with its tunnel-agent dependency
This commit is contained in:
parent
965a97105e
commit
ba521fccb4
@ -4,12 +4,12 @@ const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const caw = require('caw');
|
||||
const simpleGet = require('simple-get');
|
||||
const semver = require('semver');
|
||||
const tar = require('tar');
|
||||
const detectLibc = require('detect-libc');
|
||||
|
||||
const agent = require('./lib/agent');
|
||||
const platform = require('./lib/platform');
|
||||
|
||||
// Use NPM-provided environment variable where available, falling back to require-based method for Electron
|
||||
@ -81,9 +81,7 @@ module.exports.download_vips = function () {
|
||||
const url = distBaseUrl + tarFilename;
|
||||
const simpleGetOpt = {
|
||||
url: url,
|
||||
agent: caw(null, {
|
||||
protocol: 'https'
|
||||
})
|
||||
agent: agent()
|
||||
};
|
||||
simpleGet(simpleGetOpt, function (err, response) {
|
||||
if (err) {
|
||||
|
37
lib/agent.js
Normal file
37
lib/agent.js
Normal file
@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const url = require('url');
|
||||
const tunnelAgent = require('tunnel-agent');
|
||||
|
||||
const is = require('./is');
|
||||
|
||||
const proxies = [
|
||||
'HTTPS_PROXY',
|
||||
'https_proxy',
|
||||
'HTTP_PROXY',
|
||||
'http_proxy',
|
||||
'npm_config_https_proxy',
|
||||
'npm_config_proxy'
|
||||
];
|
||||
|
||||
function env (key) {
|
||||
return process.env[key];
|
||||
}
|
||||
|
||||
module.exports = function () {
|
||||
try {
|
||||
const proxy = url.parse(proxies.map(env).find(is.string));
|
||||
const tunnel = proxy.protocol === 'https:'
|
||||
? tunnelAgent.httpsOverHttps
|
||||
: tunnelAgent.httpsOverHttp;
|
||||
return tunnel({
|
||||
proxy: {
|
||||
port: Number(proxy.port),
|
||||
host: proxy.hostname,
|
||||
proxyAuth: proxy.auth
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
};
|
@ -69,13 +69,13 @@
|
||||
"vips"
|
||||
],
|
||||
"dependencies": {
|
||||
"caw": "^2.0.0",
|
||||
"color": "^2.0.0",
|
||||
"detect-libc": "^0.2.0",
|
||||
"detect-libc": "^1.0.2",
|
||||
"nan": "^2.7.0",
|
||||
"semver": "^5.4.1",
|
||||
"simple-get": "^2.7.0",
|
||||
"tar": "^4.0.1"
|
||||
"tar": "^4.0.1",
|
||||
"tunnel-agent": "^0.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "^2.5.0",
|
||||
@ -84,7 +84,7 @@
|
||||
"exif-reader": "^1.0.2",
|
||||
"icc": "^1.0.0",
|
||||
"mocha": "^4.0.1",
|
||||
"nyc": "^11.1.0",
|
||||
"nyc": "^11.3.0",
|
||||
"rimraf": "^2.6.1",
|
||||
"semistandard": "^11.0.0",
|
||||
"unzip": "^0.1.11"
|
||||
|
32
test/unit/agent.js
Normal file
32
test/unit/agent.js
Normal file
@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const agent = require('../../lib/agent');
|
||||
|
||||
describe('HTTP agent', function () {
|
||||
it('Without proxy', function () {
|
||||
assert.strictEqual(null, agent());
|
||||
});
|
||||
|
||||
it('HTTPS proxy with auth from HTTPS_PROXY', function () {
|
||||
process.env.HTTPS_PROXY = 'https://user:pass@secure:123';
|
||||
const proxy = agent();
|
||||
delete process.env.HTTPS_PROXY;
|
||||
assert.strictEqual('object', typeof proxy);
|
||||
assert.strictEqual('secure', proxy.options.proxy.host);
|
||||
assert.strictEqual(123, proxy.options.proxy.port);
|
||||
assert.strictEqual('user:pass', proxy.options.proxy.proxyAuth);
|
||||
assert.strictEqual(443, proxy.defaultPort);
|
||||
});
|
||||
|
||||
it('HTTP proxy without auth from npm_config_proxy', function () {
|
||||
process.env.npm_config_proxy = 'http://plaintext:456';
|
||||
const proxy = agent();
|
||||
delete process.env.npm_config_proxy;
|
||||
assert.strictEqual('object', typeof proxy);
|
||||
assert.strictEqual('plaintext', proxy.options.proxy.host);
|
||||
assert.strictEqual(456, proxy.options.proxy.port);
|
||||
assert.strictEqual(null, proxy.options.proxy.proxyAuth);
|
||||
assert.strictEqual(443, proxy.defaultPort);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user