diff --git a/index.d.ts b/index.d.ts index 0e2b0fd..4c7b53e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -17,7 +17,8 @@ export interface AxiosProxyConfig { auth?: { username: string; password:string; - } + }; + protocol?: string; } export type Method = diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8fc9e40..8225f00 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -13,6 +13,8 @@ var pkg = require('./../../package.json'); var createError = require('../core/createError'); var enhanceError = require('../core/enhanceError'); +var isHttps = /https:?/; + /*eslint consistent-return:0*/ module.exports = function httpAdapter(config) { return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) { @@ -76,8 +78,8 @@ module.exports = function httpAdapter(config) { delete headers.Authorization; } - var isHttps = protocol === 'https:'; - var agent = isHttps ? config.httpsAgent : config.httpAgent; + var isHttpsRequest = isHttps.test(protocol); + var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent; var options = { path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''), @@ -130,15 +132,16 @@ module.exports = function httpAdapter(config) { } var transport; + var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true); if (config.transport) { transport = config.transport; } else if (config.maxRedirects === 0) { - transport = isHttps ? https : http; + transport = isHttpsProxy ? https : http; } else { if (config.maxRedirects) { options.maxRedirects = config.maxRedirects; } - transport = isHttps ? httpsFollow : httpFollow; + transport = isHttpsProxy ? httpsFollow : httpFollow; } if (config.maxContentLength && config.maxContentLength > -1) {