Permalink
Browse files

Fix https request on http proxy

  • Loading branch information...
Sitronik committed Dec 28, 2017
1 parent d7f021b commit 36c1f46cb3e39b620bf81b5ba4069f1ddd02d4ce
Showing with 23 additions and 12 deletions.
  1. +1 −0 .gitignore
  2. +20 −11 lib/adapters/http.js
  3. +2 −1 package.json
@@ -7,3 +7,4 @@ typings/
coverage/
test/typescript/axios.js*
sauce_connect.log
package-lock.json
@@ -12,6 +12,7 @@ var zlib = require('zlib');
var pkg = require('./../../package.json');
var createError = require('../core/createError');
var enhanceError = require('../core/enhanceError');
var HttpsProxyAgent = require('https-proxy-agent');
/*eslint consistent-return:0*/
module.exports = function httpAdapter(config) {
@@ -71,6 +72,14 @@ module.exports = function httpAdapter(config) {
var isHttps = protocol === 'https:';
var agent = isHttps ? config.httpsAgent : config.httpAgent;
if(!agent && config.proxy && isHttps) {
if (config.proxy.auth) {
agent = new HttpsProxyAgent('http://'+config.proxy.auth.username+':'+config.proxy.auth.password+'@'+config.proxy.host+':'+config.proxy.port);
} else {
agent = new HttpsProxyAgent('http://'+config.proxy.host+':'+config.proxy.port);
}
}
var options = {
hostname: parsed.hostname,
port: parsed.port,
@@ -102,7 +111,7 @@ module.exports = function httpAdapter(config) {
}
}
if (proxy) {
if (proxy && (agent instanceof HttpsProxyAgent) === false) {
options.hostname = proxy.host;
options.host = proxy.host;
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
@@ -139,16 +148,16 @@ module.exports = function httpAdapter(config) {
// uncompress the response body transparently if required
var stream = res;
switch (res.headers['content-encoding']) {
/*eslint default-case:0*/
case 'gzip':
case 'compress':
case 'deflate':
// add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
// remove the content-encoding in order to not confuse downstream operations
delete res.headers['content-encoding'];
break;
/*eslint default-case:0*/
case 'gzip':
case 'compress':
case 'deflate':
// add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
// remove the content-encoding in order to not confuse downstream operations
delete res.headers['content-encoding'];
break;
}
// return the last request in case of redirects
@@ -74,7 +74,8 @@
"typings": "./index.d.ts",
"dependencies": {
"follow-redirects": "^1.2.5",
"is-buffer": "^1.1.5"
"is-buffer": "^1.1.5",
"https-proxy-agent": "^2.1.1"
},
"bundlesize": [
{

0 comments on commit 36c1f46

Please sign in to comment.