Skip to content

Commit 7d9a29e

Browse files
KhaledgarbayaJustinBeckwith
authored andcommitted
Fixing http adapter to allow HTTPS connections via HTTP (axios#959)
1 parent 84388b0 commit 7d9a29e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export interface AxiosProxyConfig {
1717
auth?: {
1818
username: string;
1919
password:string;
20-
}
20+
};
21+
protocol?: string;
2122
}
2223

2324
export type Method =

lib/adapters/http.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var pkg = require('./../../package.json');
1313
var createError = require('../core/createError');
1414
var enhanceError = require('../core/enhanceError');
1515

16+
var isHttps = /https:?/;
17+
1618
/*eslint consistent-return:0*/
1719
module.exports = function httpAdapter(config) {
1820
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
@@ -76,8 +78,8 @@ module.exports = function httpAdapter(config) {
7678
delete headers.Authorization;
7779
}
7880

79-
var isHttps = protocol === 'https:';
80-
var agent = isHttps ? config.httpsAgent : config.httpAgent;
81+
var isHttpsRequest = isHttps.test(protocol);
82+
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
8183

8284
var options = {
8385
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
@@ -130,15 +132,16 @@ module.exports = function httpAdapter(config) {
130132
}
131133

132134
var transport;
135+
var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
133136
if (config.transport) {
134137
transport = config.transport;
135138
} else if (config.maxRedirects === 0) {
136-
transport = isHttps ? https : http;
139+
transport = isHttpsProxy ? https : http;
137140
} else {
138141
if (config.maxRedirects) {
139142
options.maxRedirects = config.maxRedirects;
140143
}
141-
transport = isHttps ? httpsFollow : httpFollow;
144+
transport = isHttpsProxy ? httpsFollow : httpFollow;
142145
}
143146

144147
if (config.maxContentLength && config.maxContentLength > -1) {

0 commit comments

Comments
 (0)