2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-05 16:42:32 +03:00

Fixing http adapter to allow HTTPS connections via HTTP (#959)

This commit is contained in:
Khaled Garbaya
2018-07-05 08:51:11 +02:00
committed by Justin Beckwith
parent 84388b0389
commit 7d9a29ee4c
2 changed files with 9 additions and 5 deletions
Vendored
+2 -1
View File
@@ -17,7 +17,8 @@ export interface AxiosProxyConfig {
auth?: {
username: string;
password:string;
}
};
protocol?: string;
}
export type Method =
+7 -4
View File
@@ -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) {