mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Fixing http adapter to allow HTTPS connections via HTTP (#959)
This commit is contained in:
committed by
Justin Beckwith
parent
84388b0389
commit
7d9a29ee4c
Vendored
+2
-1
@@ -17,7 +17,8 @@ export interface AxiosProxyConfig {
|
|||||||
auth?: {
|
auth?: {
|
||||||
username: string;
|
username: string;
|
||||||
password:string;
|
password:string;
|
||||||
}
|
};
|
||||||
|
protocol?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Method =
|
export type Method =
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ var pkg = require('./../../package.json');
|
|||||||
var createError = require('../core/createError');
|
var createError = require('../core/createError');
|
||||||
var enhanceError = require('../core/enhanceError');
|
var enhanceError = require('../core/enhanceError');
|
||||||
|
|
||||||
|
var isHttps = /https:?/;
|
||||||
|
|
||||||
/*eslint consistent-return:0*/
|
/*eslint consistent-return:0*/
|
||||||
module.exports = function httpAdapter(config) {
|
module.exports = function httpAdapter(config) {
|
||||||
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
||||||
@@ -76,8 +78,8 @@ module.exports = function httpAdapter(config) {
|
|||||||
delete headers.Authorization;
|
delete headers.Authorization;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isHttps = protocol === 'https:';
|
var isHttpsRequest = isHttps.test(protocol);
|
||||||
var agent = isHttps ? config.httpsAgent : config.httpAgent;
|
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||||
@@ -130,15 +132,16 @@ module.exports = function httpAdapter(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var transport;
|
var transport;
|
||||||
|
var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
|
||||||
if (config.transport) {
|
if (config.transport) {
|
||||||
transport = config.transport;
|
transport = config.transport;
|
||||||
} else if (config.maxRedirects === 0) {
|
} else if (config.maxRedirects === 0) {
|
||||||
transport = isHttps ? https : http;
|
transport = isHttpsProxy ? https : http;
|
||||||
} else {
|
} else {
|
||||||
if (config.maxRedirects) {
|
if (config.maxRedirects) {
|
||||||
options.maxRedirects = config.maxRedirects;
|
options.maxRedirects = config.maxRedirects;
|
||||||
}
|
}
|
||||||
transport = isHttps ? httpsFollow : httpFollow;
|
transport = isHttpsProxy ? httpsFollow : httpFollow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.maxContentLength && config.maxContentLength > -1) {
|
if (config.maxContentLength && config.maxContentLength > -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user