2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +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
+33
View File
@@ -20,6 +20,7 @@ const isBlobSupported = typeof Blob !== 'undefined';
import {Throttle} from 'stream-throttle';
import devNull from 'dev-null';
import {AbortController} from 'abortcontroller-polyfill/dist/cjs-ponyfill.js';
import {__setProxy} from "../../../lib/adapters/http.js";
const __filename = url.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -1236,6 +1237,38 @@ describe('supports http with nodejs', function () {
});
});
context('different options for direct proxy configuration (without env variables)', () => {
const destination = 'www.example.com';
const testCases = [{
description: 'hostname and trailing colon in protocol',
proxyConfig: { hostname: '127.0.0.1', protocol: 'http:', port: 80 },
expectedOptions: { host: '127.0.0.1', protocol: 'http:', port: 80, path: destination }
}, {
description: 'hostname and no trailing colon in protocol',
proxyConfig: { hostname: '127.0.0.1', protocol: 'http', port: 80 },
expectedOptions: { host: '127.0.0.1', protocol: 'http:', port: 80, path: destination }
}, {
description: 'both hostname and host -> hostname takes precedence',
proxyConfig: { hostname: '127.0.0.1', host: '0.0.0.0', protocol: 'http', port: 80 },
expectedOptions: { host: '127.0.0.1', protocol: 'http:', port: 80, path: destination }
}, {
description: 'only host and https protocol',
proxyConfig: { host: '0.0.0.0', protocol: 'https', port: 80 },
expectedOptions: { host: '0.0.0.0', protocol: 'https:', port: 80, path: destination }
}];
for (const test of testCases) {
it(test.description, () => {
const options = { headers: {}, beforeRedirects: {} };
__setProxy(options, test.proxyConfig, destination);
for (const [key, expected] of Object.entries(test.expectedOptions)) {
assert.equal(options[key], expected);
}
});
}
});
it('should support cancel', function (done) {
var source = axios.CancelToken.source();
server = http.createServer(function (req, res) {