2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

fix: restore proxy config backwards compatibility with 0.x (#5097)

* fix: restore proxy config backwards compatibility with 0.x

* Formatting

Co-authored-by: Patrick Petrovic <patrick@Air-de-Patrick.lan>
Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Patrick Petrovic
2022-10-13 20:55:20 +01:00
committed by GitHub
parent 83454a55f6
commit 717f476b0f
3 changed files with 41 additions and 4 deletions
+7 -4
View File
@@ -51,7 +51,7 @@ function dispatchBeforeRedirect(options) {
* If the proxy or config afterRedirects functions are defined, call them with the options
*
* @param {http.ClientRequestArgs} options
* @param {AxiosProxyConfig} configProxy
* @param {AxiosProxyConfig} configProxy configuration from Axios options object
* @param {string} location
*
* @returns {http.ClientRequestArgs}
@@ -82,13 +82,14 @@ function setProxy(options, configProxy, location) {
}
options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
options.hostname = proxy.hostname;
const proxyHost = proxy.hostname || proxy.host;
options.hostname = proxyHost;
// Replace 'host' since options is not a URL object
options.host = proxy.hostname;
options.host = proxyHost;
options.port = proxy.port;
options.path = location;
if (proxy.protocol) {
options.protocol = proxy.protocol;
options.protocol = proxy.protocol.includes(':') ? proxy.protocol : `${proxy.protocol}:`;
}
}
@@ -586,3 +587,5 @@ export default function httpAdapter(config) {
}
});
}
export const __setProxy = setProxy;