This commit is contained in:
2025-06-26 04:42:51 +00:00
parent be418b1f32
commit 78212cc2a9
183 changed files with 41796 additions and 0 deletions

View File

@@ -0,0 +1,483 @@
/* eslint max-statements:0 */
'use strict';
var assert = require('assert');
var parseUrl = require('url').parse;
var getProxyForUrl = require('./').getProxyForUrl;
// Runs the callback with process.env temporarily set to env.
function runWithEnv(env, callback) {
var originalEnv = process.env;
process.env = env;
try {
callback();
} finally {
process.env = originalEnv;
}
}
// Defines a test case that checks whether getProxyForUrl(input) === expected.
function testProxyUrl(env, expected, input) {
assert(typeof env === 'object' && env !== null);
// Copy object to make sure that the in param does not get modified between
// the call of this function and the use of it below.
env = JSON.parse(JSON.stringify(env));
var title = 'getProxyForUrl(' + JSON.stringify(input) + ')' +
' === ' + JSON.stringify(expected);
// Save call stack for later use.
var stack = {};
Error.captureStackTrace(stack, testProxyUrl);
// Only use the last stack frame because that shows where this function is
// called, and that is sufficient for our purpose. No need to flood the logs
// with an uninteresting stack trace.
stack = stack.stack.split('\n', 2)[1];
it(title, function() {
var actual;
runWithEnv(env, function() {
actual = getProxyForUrl(input);
});
if (expected === actual) {
return; // Good!
}
try {
assert.strictEqual(expected, actual); // Create a formatted error message.
// Should not happen because previously we determined expected !== actual.
throw new Error('assert.strictEqual passed. This is impossible!');
} catch (e) {
// Use the original stack trace, so we can see a helpful line number.
e.stack = e.message + stack;
throw e;
}
});
}
describe('getProxyForUrl', function() {
describe('No proxy variables', function() {
var env = {};
testProxyUrl(env, '', 'http://example.com');
testProxyUrl(env, '', 'https://example.com');
testProxyUrl(env, '', 'ftp://example.com');
});
describe('Invalid URLs', function() {
var env = {};
env.ALL_PROXY = 'http://unexpected.proxy';
testProxyUrl(env, '', 'bogus');
testProxyUrl(env, '', '//example.com');
testProxyUrl(env, '', '://example.com');
testProxyUrl(env, '', '://');
testProxyUrl(env, '', '/path');
testProxyUrl(env, '', '');
testProxyUrl(env, '', 'http:');
testProxyUrl(env, '', 'http:/');
testProxyUrl(env, '', 'http://');
testProxyUrl(env, '', 'prototype://');
testProxyUrl(env, '', 'hasOwnProperty://');
testProxyUrl(env, '', '__proto__://');
testProxyUrl(env, '', undefined);
testProxyUrl(env, '', null);
testProxyUrl(env, '', {});
testProxyUrl(env, '', {host: 'x', protocol: 1});
testProxyUrl(env, '', {host: 1, protocol: 'x'});
});
describe('http_proxy and HTTP_PROXY', function() {
var env = {};
env.HTTP_PROXY = 'http://http-proxy';
testProxyUrl(env, '', 'https://example');
testProxyUrl(env, 'http://http-proxy', 'http://example');
testProxyUrl(env, 'http://http-proxy', parseUrl('http://example'));
// eslint-disable-next-line camelcase
env.http_proxy = 'http://priority';
testProxyUrl(env, 'http://priority', 'http://example');
});
describe('http_proxy with non-sensical value', function() {
var env = {};
// Crazy values should be passed as-is. It is the responsibility of the
// one who launches the application that the value makes sense.
// TODO: Should we be stricter and perform validation?
env.HTTP_PROXY = 'Crazy \n!() { ::// }';
testProxyUrl(env, 'Crazy \n!() { ::// }', 'http://wow');
// The implementation assumes that the HTTP_PROXY environment variable is
// somewhat reasonable, and if the scheme is missing, it is added.
// Garbage in, garbage out some would say...
env.HTTP_PROXY = 'crazy without colon slash slash';
testProxyUrl(env, 'http://crazy without colon slash slash', 'http://wow');
});
describe('https_proxy and HTTPS_PROXY', function() {
var env = {};
// Assert that there is no fall back to http_proxy
env.HTTP_PROXY = 'http://unexpected.proxy';
testProxyUrl(env, '', 'https://example');
env.HTTPS_PROXY = 'http://https-proxy';
testProxyUrl(env, 'http://https-proxy', 'https://example');
// eslint-disable-next-line camelcase
env.https_proxy = 'http://priority';
testProxyUrl(env, 'http://priority', 'https://example');
});
describe('ftp_proxy', function() {
var env = {};
// Something else than http_proxy / https, as a sanity check.
env.FTP_PROXY = 'http://ftp-proxy';
testProxyUrl(env, 'http://ftp-proxy', 'ftp://example');
testProxyUrl(env, '', 'ftps://example');
});
describe('all_proxy', function() {
var env = {};
env.ALL_PROXY = 'http://catch-all';
testProxyUrl(env, 'http://catch-all', 'https://example');
// eslint-disable-next-line camelcase
env.all_proxy = 'http://priority';
testProxyUrl(env, 'http://priority', 'https://example');
});
describe('all_proxy without scheme', function() {
var env = {};
env.ALL_PROXY = 'noscheme';
testProxyUrl(env, 'http://noscheme', 'http://example');
testProxyUrl(env, 'https://noscheme', 'https://example');
// The module does not impose restrictions on the scheme.
testProxyUrl(env, 'bogus-scheme://noscheme', 'bogus-scheme://example');
// But the URL should still be valid.
testProxyUrl(env, '', 'bogus');
});
describe('no_proxy empty', function() {
var env = {};
env.HTTPS_PROXY = 'http://proxy';
// NO_PROXY set but empty.
env.NO_PROXY = '';
testProxyUrl(env, 'http://proxy', 'https://example');
// No entries in NO_PROXY (comma).
env.NO_PROXY = ',';
testProxyUrl(env, 'http://proxy', 'https://example');
// No entries in NO_PROXY (whitespace).
env.NO_PROXY = ' ';
testProxyUrl(env, 'http://proxy', 'https://example');
// No entries in NO_PROXY (multiple whitespace / commas).
env.NO_PROXY = ',\t,,,\n, ,\r';
testProxyUrl(env, 'http://proxy', 'https://example');
});
describe('no_proxy=example (single host)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = 'example';
testProxyUrl(env, '', 'http://example');
testProxyUrl(env, '', 'http://example:80');
testProxyUrl(env, '', 'http://example:0');
testProxyUrl(env, '', 'http://example:1337');
testProxyUrl(env, 'http://proxy', 'http://sub.example');
testProxyUrl(env, 'http://proxy', 'http://prefexample');
testProxyUrl(env, 'http://proxy', 'http://example.no');
testProxyUrl(env, 'http://proxy', 'http://a.b.example');
testProxyUrl(env, 'http://proxy', 'http://host/example');
});
describe('no_proxy=sub.example (subdomain)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = 'sub.example';
testProxyUrl(env, 'http://proxy', 'http://example');
testProxyUrl(env, 'http://proxy', 'http://example:80');
testProxyUrl(env, 'http://proxy', 'http://example:0');
testProxyUrl(env, 'http://proxy', 'http://example:1337');
testProxyUrl(env, '', 'http://sub.example');
testProxyUrl(env, 'http://proxy', 'http://no.sub.example');
testProxyUrl(env, 'http://proxy', 'http://sub-example');
testProxyUrl(env, 'http://proxy', 'http://example.sub');
});
describe('no_proxy=example:80 (host + port)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = 'example:80';
testProxyUrl(env, '', 'http://example');
testProxyUrl(env, '', 'http://example:80');
testProxyUrl(env, '', 'http://example:0');
testProxyUrl(env, 'http://proxy', 'http://example:1337');
testProxyUrl(env, 'http://proxy', 'http://sub.example');
testProxyUrl(env, 'http://proxy', 'http://prefexample');
testProxyUrl(env, 'http://proxy', 'http://example.no');
testProxyUrl(env, 'http://proxy', 'http://a.b.example');
});
describe('no_proxy=.example (host suffix)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '.example';
testProxyUrl(env, 'http://proxy', 'http://example');
testProxyUrl(env, 'http://proxy', 'http://example:80');
testProxyUrl(env, 'http://proxy', 'http://example:1337');
testProxyUrl(env, '', 'http://sub.example');
testProxyUrl(env, '', 'http://sub.example:80');
testProxyUrl(env, '', 'http://sub.example:1337');
testProxyUrl(env, 'http://proxy', 'http://prefexample');
testProxyUrl(env, 'http://proxy', 'http://example.no');
testProxyUrl(env, '', 'http://a.b.example');
});
describe('no_proxy=*', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '*';
testProxyUrl(env, '', 'http://example.com');
});
describe('no_proxy=*.example (host suffix with *.)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '*.example';
testProxyUrl(env, 'http://proxy', 'http://example');
testProxyUrl(env, 'http://proxy', 'http://example:80');
testProxyUrl(env, 'http://proxy', 'http://example:1337');
testProxyUrl(env, '', 'http://sub.example');
testProxyUrl(env, '', 'http://sub.example:80');
testProxyUrl(env, '', 'http://sub.example:1337');
testProxyUrl(env, 'http://proxy', 'http://prefexample');
testProxyUrl(env, 'http://proxy', 'http://example.no');
testProxyUrl(env, '', 'http://a.b.example');
});
describe('no_proxy=*example (substring suffix)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '*example';
testProxyUrl(env, '', 'http://example');
testProxyUrl(env, '', 'http://example:80');
testProxyUrl(env, '', 'http://example:1337');
testProxyUrl(env, '', 'http://sub.example');
testProxyUrl(env, '', 'http://sub.example:80');
testProxyUrl(env, '', 'http://sub.example:1337');
testProxyUrl(env, '', 'http://prefexample');
testProxyUrl(env, '', 'http://a.b.example');
testProxyUrl(env, 'http://proxy', 'http://example.no');
testProxyUrl(env, 'http://proxy', 'http://host/example');
});
describe('no_proxy=.*example (arbitrary wildcards are NOT supported)',
function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '.*example';
testProxyUrl(env, 'http://proxy', 'http://example');
testProxyUrl(env, 'http://proxy', 'http://sub.example');
testProxyUrl(env, 'http://proxy', 'http://sub.example');
testProxyUrl(env, 'http://proxy', 'http://prefexample');
testProxyUrl(env, 'http://proxy', 'http://x.prefexample');
testProxyUrl(env, 'http://proxy', 'http://a.b.example');
});
describe('no_proxy=[::1],[::2]:80,10.0.0.1,10.0.0.2:80 (IP addresses)',
function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '[::1],[::2]:80,10.0.0.1,10.0.0.2:80';
testProxyUrl(env, '', 'http://[::1]/');
testProxyUrl(env, '', 'http://[::1]:80/');
testProxyUrl(env, '', 'http://[::1]:1337/');
testProxyUrl(env, '', 'http://[::2]/');
testProxyUrl(env, '', 'http://[::2]:80/');
testProxyUrl(env, 'http://proxy', 'http://[::2]:1337/');
testProxyUrl(env, '', 'http://10.0.0.1/');
testProxyUrl(env, '', 'http://10.0.0.1:80/');
testProxyUrl(env, '', 'http://10.0.0.1:1337/');
testProxyUrl(env, '', 'http://10.0.0.2/');
testProxyUrl(env, '', 'http://10.0.0.2:80/');
testProxyUrl(env, 'http://proxy', 'http://10.0.0.2:1337/');
});
describe('no_proxy=127.0.0.1/32 (CIDR is NOT supported)', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '127.0.0.1/32';
testProxyUrl(env, 'http://proxy', 'http://127.0.0.1');
testProxyUrl(env, 'http://proxy', 'http://127.0.0.1/32');
});
describe('no_proxy=127.0.0.1 does NOT match localhost', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = '127.0.0.1';
testProxyUrl(env, '', 'http://127.0.0.1');
// We're not performing DNS queries, so this shouldn't match.
testProxyUrl(env, 'http://proxy', 'http://localhost');
});
describe('no_proxy with protocols that have a default port', function() {
var env = {};
env.WS_PROXY = 'http://ws';
env.WSS_PROXY = 'http://wss';
env.HTTP_PROXY = 'http://http';
env.HTTPS_PROXY = 'http://https';
env.GOPHER_PROXY = 'http://gopher';
env.FTP_PROXY = 'http://ftp';
env.ALL_PROXY = 'http://all';
env.NO_PROXY = 'xxx:21,xxx:70,xxx:80,xxx:443';
testProxyUrl(env, '', 'http://xxx');
testProxyUrl(env, '', 'http://xxx:80');
testProxyUrl(env, 'http://http', 'http://xxx:1337');
testProxyUrl(env, '', 'ws://xxx');
testProxyUrl(env, '', 'ws://xxx:80');
testProxyUrl(env, 'http://ws', 'ws://xxx:1337');
testProxyUrl(env, '', 'https://xxx');
testProxyUrl(env, '', 'https://xxx:443');
testProxyUrl(env, 'http://https', 'https://xxx:1337');
testProxyUrl(env, '', 'wss://xxx');
testProxyUrl(env, '', 'wss://xxx:443');
testProxyUrl(env, 'http://wss', 'wss://xxx:1337');
testProxyUrl(env, '', 'gopher://xxx');
testProxyUrl(env, '', 'gopher://xxx:70');
testProxyUrl(env, 'http://gopher', 'gopher://xxx:1337');
testProxyUrl(env, '', 'ftp://xxx');
testProxyUrl(env, '', 'ftp://xxx:21');
testProxyUrl(env, 'http://ftp', 'ftp://xxx:1337');
});
describe('no_proxy should not be case-sensitive', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = 'XXX,YYY,ZzZ';
testProxyUrl(env, '', 'http://xxx');
testProxyUrl(env, '', 'http://XXX');
testProxyUrl(env, '', 'http://yyy');
testProxyUrl(env, '', 'http://YYY');
testProxyUrl(env, '', 'http://ZzZ');
testProxyUrl(env, '', 'http://zZz');
});
describe('NPM proxy configuration', function() {
describe('npm_config_http_proxy should work', function() {
var env = {};
// eslint-disable-next-line camelcase
env.npm_config_http_proxy = 'http://http-proxy';
testProxyUrl(env, '', 'https://example');
testProxyUrl(env, 'http://http-proxy', 'http://example');
// eslint-disable-next-line camelcase
env.npm_config_http_proxy = 'http://priority';
testProxyUrl(env, 'http://priority', 'http://example');
});
// eslint-disable-next-line max-len
describe('npm_config_http_proxy should take precedence over HTTP_PROXY and npm_config_proxy', function() {
var env = {};
// eslint-disable-next-line camelcase
env.npm_config_http_proxy = 'http://http-proxy';
// eslint-disable-next-line camelcase
env.npm_config_proxy = 'http://unexpected-proxy';
env.HTTP_PROXY = 'http://unexpected-proxy';
testProxyUrl(env, 'http://http-proxy', 'http://example');
});
describe('npm_config_https_proxy should work', function() {
var env = {};
// eslint-disable-next-line camelcase
env.npm_config_http_proxy = 'http://unexpected.proxy';
testProxyUrl(env, '', 'https://example');
// eslint-disable-next-line camelcase
env.npm_config_https_proxy = 'http://https-proxy';
testProxyUrl(env, 'http://https-proxy', 'https://example');
// eslint-disable-next-line camelcase
env.npm_config_https_proxy = 'http://priority';
testProxyUrl(env, 'http://priority', 'https://example');
});
// eslint-disable-next-line max-len
describe('npm_config_https_proxy should take precedence over HTTPS_PROXY and npm_config_proxy', function() {
var env = {};
// eslint-disable-next-line camelcase
env.npm_config_https_proxy = 'http://https-proxy';
// eslint-disable-next-line camelcase
env.npm_config_proxy = 'http://unexpected-proxy';
env.HTTPS_PROXY = 'http://unexpected-proxy';
testProxyUrl(env, 'http://https-proxy', 'https://example');
});
describe('npm_config_proxy should work', function() {
var env = {};
// eslint-disable-next-line camelcase
env.npm_config_proxy = 'http://http-proxy';
testProxyUrl(env, 'http://http-proxy', 'http://example');
testProxyUrl(env, 'http://http-proxy', 'https://example');
// eslint-disable-next-line camelcase
env.npm_config_proxy = 'http://priority';
testProxyUrl(env, 'http://priority', 'http://example');
testProxyUrl(env, 'http://priority', 'https://example');
});
// eslint-disable-next-line max-len
describe('HTTP_PROXY and HTTPS_PROXY should take precedence over npm_config_proxy', function() {
var env = {};
env.HTTP_PROXY = 'http://http-proxy';
env.HTTPS_PROXY = 'http://https-proxy';
// eslint-disable-next-line camelcase
env.npm_config_proxy = 'http://unexpected-proxy';
testProxyUrl(env, 'http://http-proxy', 'http://example');
testProxyUrl(env, 'http://https-proxy', 'https://example');
});
describe('npm_config_no_proxy should work', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
// eslint-disable-next-line camelcase
env.npm_config_no_proxy = 'example';
testProxyUrl(env, '', 'http://example');
testProxyUrl(env, 'http://proxy', 'http://otherwebsite');
});
// eslint-disable-next-line max-len
describe('npm_config_no_proxy should take precedence over NO_PROXY', function() {
var env = {};
env.HTTP_PROXY = 'http://proxy';
env.NO_PROXY = 'otherwebsite';
// eslint-disable-next-line camelcase
env.npm_config_no_proxy = 'example';
testProxyUrl(env, '', 'http://example');
testProxyUrl(env, 'http://proxy', 'http://otherwebsite');
});
});
});

View File

@@ -0,0 +1,161 @@
'use strict';
import utils from '../utils.js';
import AxiosError from '../core/AxiosError.js';
import transitionalDefaults from './transitional.js';
import toFormData from '../helpers/toFormData.js';
import toURLEncodedForm from '../helpers/toURLEncodedForm.js';
import platform from '../platform/index.js';
import formDataToJSON from '../helpers/formDataToJSON.js';
/**
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
* of the input
*
* @param {any} rawValue - The value to be stringified.
* @param {Function} parser - A function that parses a string into a JavaScript object.
* @param {Function} encoder - A function that takes a value and returns a string.
*
* @returns {string} A stringified version of the rawValue.
*/
function stringifySafely(rawValue, parser, encoder) {
if (utils.isString(rawValue)) {
try {
(parser || JSON.parse)(rawValue);
return utils.trim(rawValue);
} catch (e) {
if (e.name !== 'SyntaxError') {
throw e;
}
}
}
return (encoder || JSON.stringify)(rawValue);
}
const defaults = {
transitional: transitionalDefaults,
adapter: ['xhr', 'http', 'fetch'],
transformRequest: [function transformRequest(data, headers) {
const contentType = headers.getContentType() || '';
const hasJSONContentType = contentType.indexOf('application/json') > -1;
const isObjectPayload = utils.isObject(data);
if (isObjectPayload && utils.isHTMLForm(data)) {
data = new FormData(data);
}
const isFormData = utils.isFormData(data);
if (isFormData) {
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
}
if (utils.isArrayBuffer(data) ||
utils.isBuffer(data) ||
utils.isStream(data) ||
utils.isFile(data) ||
utils.isBlob(data) ||
utils.isReadableStream(data)
) {
return data;
}
if (utils.isArrayBufferView(data)) {
return data.buffer;
}
if (utils.isURLSearchParams(data)) {
headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
return data.toString();
}
let isFileList;
if (isObjectPayload) {
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
return toURLEncodedForm(data, this.formSerializer).toString();
}
if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
const _FormData = this.env && this.env.FormData;
return toFormData(
isFileList ? {'files[]': data} : data,
_FormData && new _FormData(),
this.formSerializer
);
}
}
if (isObjectPayload || hasJSONContentType ) {
headers.setContentType('application/json', false);
return stringifySafely(data);
}
return data;
}],
transformResponse: [function transformResponse(data) {
const transitional = this.transitional || defaults.transitional;
const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
const JSONRequested = this.responseType === 'json';
if (utils.isResponse(data) || utils.isReadableStream(data)) {
return data;
}
if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
const silentJSONParsing = transitional && transitional.silentJSONParsing;
const strictJSONParsing = !silentJSONParsing && JSONRequested;
try {
return JSON.parse(data);
} catch (e) {
if (strictJSONParsing) {
if (e.name === 'SyntaxError') {
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
}
throw e;
}
}
}
return data;
}],
/**
* A timeout in milliseconds to abort a request. If set to 0 (default) a
* timeout is not created.
*/
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: {
FormData: platform.classes.FormData,
Blob: platform.classes.Blob
},
validateStatus: function validateStatus(status) {
return status >= 200 && status < 300;
},
headers: {
common: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': undefined
}
}
};
utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
defaults.headers[method] = {};
});
export default defaults;

View File

@@ -0,0 +1,550 @@
interface RawAxiosHeaders {
[key: string]: axios.AxiosHeaderValue;
}
type MethodsHeaders = Partial<{
[Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
} & {common: AxiosHeaders}>;
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
type AxiosHeaderParser = (this: AxiosHeaders, value: axios.AxiosHeaderValue, header: string) => any;
type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent'| 'Content-Encoding' | 'Authorization';
type ContentType = axios.AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
declare class AxiosHeaders {
constructor(
headers?: RawAxiosHeaders | AxiosHeaders | string
);
[key: string]: any;
set(headerName?: string, value?: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
get(headerName: string, parser: RegExp): RegExpExecArray | null;
get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
has(header: string, matcher?: AxiosHeaderMatcher): boolean;
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
clear(matcher?: AxiosHeaderMatcher): boolean;
normalize(format: boolean): AxiosHeaders;
concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
toJSON(asStrings?: boolean): RawAxiosHeaders;
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
static accessor(header: string | string[]): AxiosHeaders;
static concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
setContentType(value: ContentType, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
getContentType(parser?: RegExp): RegExpExecArray | null;
getContentType(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
hasContentType(matcher?: AxiosHeaderMatcher): boolean;
setContentLength(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
getContentLength(parser?: RegExp): RegExpExecArray | null;
getContentLength(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
setAccept(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
getAccept(parser?: RegExp): RegExpExecArray | null;
getAccept(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
hasAccept(matcher?: AxiosHeaderMatcher): boolean;
setUserAgent(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
getUserAgent(parser?: RegExp): RegExpExecArray | null;
getUserAgent(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
setContentEncoding(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
getContentEncoding(parser?: RegExp): RegExpExecArray | null;
getContentEncoding(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
setAuthorization(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
getAuthorization(parser?: RegExp): RegExpExecArray | null;
getAuthorization(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
[Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
}
declare class AxiosError<T = unknown, D = any> extends Error {
constructor(
message?: string,
code?: string,
config?: axios.InternalAxiosRequestConfig<D>,
request?: any,
response?: axios.AxiosResponse<T, D>
);
config?: axios.InternalAxiosRequestConfig<D>;
code?: string;
request?: any;
response?: axios.AxiosResponse<T, D>;
isAxiosError: boolean;
status?: number;
toJSON: () => object;
cause?: Error;
static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
static readonly ERR_NETWORK = "ERR_NETWORK";
static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
static readonly ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
static readonly ERR_INVALID_URL = "ERR_INVALID_URL";
static readonly ERR_CANCELED = "ERR_CANCELED";
static readonly ECONNABORTED = "ECONNABORTED";
static readonly ETIMEDOUT = "ETIMEDOUT";
}
declare class CanceledError<T> extends AxiosError<T> {
}
declare class Axios {
constructor(config?: axios.AxiosRequestConfig);
defaults: axios.AxiosDefaults;
interceptors: {
request: axios.AxiosInterceptorManager<axios.InternalAxiosRequestConfig>;
response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
};
getUri(config?: axios.AxiosRequestConfig): string;
request<T = any, R = axios.AxiosResponse<T>, D = any>(config: axios.AxiosRequestConfig<D>): Promise<R>;
get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
postForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
putForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
}
declare enum HttpStatusCode {
Continue = 100,
SwitchingProtocols = 101,
Processing = 102,
EarlyHints = 103,
Ok = 200,
Created = 201,
Accepted = 202,
NonAuthoritativeInformation = 203,
NoContent = 204,
ResetContent = 205,
PartialContent = 206,
MultiStatus = 207,
AlreadyReported = 208,
ImUsed = 226,
MultipleChoices = 300,
MovedPermanently = 301,
Found = 302,
SeeOther = 303,
NotModified = 304,
UseProxy = 305,
Unused = 306,
TemporaryRedirect = 307,
PermanentRedirect = 308,
BadRequest = 400,
Unauthorized = 401,
PaymentRequired = 402,
Forbidden = 403,
NotFound = 404,
MethodNotAllowed = 405,
NotAcceptable = 406,
ProxyAuthenticationRequired = 407,
RequestTimeout = 408,
Conflict = 409,
Gone = 410,
LengthRequired = 411,
PreconditionFailed = 412,
PayloadTooLarge = 413,
UriTooLong = 414,
UnsupportedMediaType = 415,
RangeNotSatisfiable = 416,
ExpectationFailed = 417,
ImATeapot = 418,
MisdirectedRequest = 421,
UnprocessableEntity = 422,
Locked = 423,
FailedDependency = 424,
TooEarly = 425,
UpgradeRequired = 426,
PreconditionRequired = 428,
TooManyRequests = 429,
RequestHeaderFieldsTooLarge = 431,
UnavailableForLegalReasons = 451,
InternalServerError = 500,
NotImplemented = 501,
BadGateway = 502,
ServiceUnavailable = 503,
GatewayTimeout = 504,
HttpVersionNotSupported = 505,
VariantAlsoNegotiates = 506,
InsufficientStorage = 507,
LoopDetected = 508,
NotExtended = 510,
NetworkAuthenticationRequired = 511,
}
type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
declare namespace axios {
type AxiosError<T = unknown, D = any> = InternalAxiosError<T, D>;
type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & {
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
} & {
'Content-Type': ContentType
}>;
type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
type RawCommonResponseHeaders = {
[Key in CommonResponseHeadersList]: AxiosHeaderValue;
} & {
"set-cookie": string[];
};
type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
interface AxiosRequestTransformer {
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
}
interface AxiosResponseTransformer {
(this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
}
interface AxiosAdapter {
(config: InternalAxiosRequestConfig): AxiosPromise;
}
interface AxiosBasicCredentials {
username: string;
password: string;
}
interface AxiosProxyConfig {
host: string;
port: number;
auth?: AxiosBasicCredentials;
protocol?: string;
}
type Method =
| 'get' | 'GET'
| 'delete' | 'DELETE'
| 'head' | 'HEAD'
| 'options' | 'OPTIONS'
| 'post' | 'POST'
| 'put' | 'PUT'
| 'patch' | 'PATCH'
| 'purge' | 'PURGE'
| 'link' | 'LINK'
| 'unlink' | 'UNLINK';
type ResponseType =
| 'arraybuffer'
| 'blob'
| 'document'
| 'json'
| 'text'
| 'stream'
| 'formdata';
type responseEncoding =
| 'ascii' | 'ASCII'
| 'ansi' | 'ANSI'
| 'binary' | 'BINARY'
| 'base64' | 'BASE64'
| 'base64url' | 'BASE64URL'
| 'hex' | 'HEX'
| 'latin1' | 'LATIN1'
| 'ucs-2' | 'UCS-2'
| 'ucs2' | 'UCS2'
| 'utf-8' | 'UTF-8'
| 'utf8' | 'UTF8'
| 'utf16le' | 'UTF16LE';
interface TransitionalOptions {
silentJSONParsing?: boolean;
forcedJSONParsing?: boolean;
clarifyTimeoutError?: boolean;
}
interface GenericAbortSignal {
readonly aborted: boolean;
onabort?: ((...args: any) => any) | null;
addEventListener?: (...args: any) => any;
removeEventListener?: (...args: any) => any;
}
interface FormDataVisitorHelpers {
defaultVisitor: SerializerVisitor;
convertValue: (value: any) => any;
isVisitable: (value: any) => boolean;
}
interface SerializerVisitor {
(
this: GenericFormData,
value: any,
key: string | number,
path: null | Array<string | number>,
helpers: FormDataVisitorHelpers
): boolean;
}
interface SerializerOptions {
visitor?: SerializerVisitor;
dots?: boolean;
metaTokens?: boolean;
indexes?: boolean | null;
}
// tslint:disable-next-line
interface FormSerializerOptions extends SerializerOptions {
}
interface ParamEncoder {
(value: any, defaultEncoder: (value: any) => any): any;
}
interface CustomParamsSerializer {
(params: Record<string, any>, options?: ParamsSerializerOptions): string;
}
interface ParamsSerializerOptions extends SerializerOptions {
encode?: ParamEncoder;
serialize?: CustomParamsSerializer;
}
type MaxUploadRate = number;
type MaxDownloadRate = number;
type BrowserProgressEvent = any;
interface AxiosProgressEvent {
loaded: number;
total?: number;
progress?: number;
bytes: number;
rate?: number;
estimated?: number;
upload?: boolean;
download?: boolean;
event?: BrowserProgressEvent;
lengthComputable: boolean;
}
type Milliseconds = number;
type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | (string & {});
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
type AddressFamily = 4 | 6 | undefined;
interface LookupAddressEntry {
address: string;
family?: AddressFamily;
}
type LookupAddress = string | LookupAddressEntry;
interface AxiosRequestConfig<D = any> {
url?: string;
method?: Method | string;
baseURL?: string;
allowAbsoluteUrls?: boolean;
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
params?: any;
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
data?: D;
timeout?: Milliseconds;
timeoutErrorMessage?: string;
withCredentials?: boolean;
adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
auth?: AxiosBasicCredentials;
responseType?: ResponseType;
responseEncoding?: responseEncoding | string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
maxContentLength?: number;
validateStatus?: ((status: number) => boolean) | null;
maxBodyLength?: number;
maxRedirects?: number;
maxRate?: number | [MaxUploadRate, MaxDownloadRate];
beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>, statusCode: HttpStatusCode}) => void;
socketPath?: string | null;
transport?: any;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig | false;
cancelToken?: CancelToken;
decompress?: boolean;
transitional?: TransitionalOptions;
signal?: GenericAbortSignal;
insecureHTTPParser?: boolean;
env?: {
FormData?: new (...args: any[]) => object;
};
formSerializer?: FormSerializerOptions;
family?: AddressFamily;
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
}
// Alias
type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig {
headers: AxiosRequestHeaders;
}
interface HeadersDefaults {
common: RawAxiosRequestHeaders;
delete: RawAxiosRequestHeaders;
get: RawAxiosRequestHeaders;
head: RawAxiosRequestHeaders;
post: RawAxiosRequestHeaders;
put: RawAxiosRequestHeaders;
patch: RawAxiosRequestHeaders;
options?: RawAxiosRequestHeaders;
purge?: RawAxiosRequestHeaders;
link?: RawAxiosRequestHeaders;
unlink?: RawAxiosRequestHeaders;
}
interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
headers: HeadersDefaults;
}
interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
}
interface AxiosResponse<T = any, D = any> {
data: T;
status: number;
statusText: string;
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
config: InternalAxiosRequestConfig<D>;
request?: any;
}
type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
interface CancelStatic {
new (message?: string): Cancel;
}
interface Cancel {
message: string | undefined;
}
interface Canceler {
(message?: string, config?: AxiosRequestConfig, request?: any): void;
}
interface CancelTokenStatic {
new (executor: (cancel: Canceler) => void): CancelToken;
source(): CancelTokenSource;
}
interface CancelToken {
promise: Promise<Cancel>;
reason?: Cancel;
throwIfRequested(): void;
}
interface CancelTokenSource {
token: CancelToken;
cancel: Canceler;
}
interface AxiosInterceptorOptions {
synchronous?: boolean;
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
}
type AxiosRequestInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions) => number;
type AxiosResponseInterceptorUse<T> = (onFulfilled?: ((value: T) => T | Promise<T>) | null, onRejected?: ((error: any) => any) | null) => number;
interface AxiosInterceptorManager<V> {
use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
eject(id: number): void;
clear(): void;
}
interface AxiosInstance extends Axios {
<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
create(config?: CreateAxiosDefaults): AxiosInstance;
defaults: Omit<AxiosDefaults, 'headers'> & {
headers: HeadersDefaults & {
[key: string]: AxiosHeaderValue
}
};
}
interface GenericFormData {
append(name: string, value: any, options?: any): any;
}
interface GenericHTMLFormElement {
name: string;
method: string;
submit(): void;
}
interface AxiosStatic extends AxiosInstance {
Cancel: CancelStatic;
CancelToken: CancelTokenStatic;
Axios: typeof Axios;
AxiosError: typeof AxiosError;
CanceledError: typeof CanceledError;
HttpStatusCode: typeof HttpStatusCode;
readonly VERSION: string;
isCancel(value: any): value is Cancel;
all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
AxiosHeaders: typeof AxiosHeaders;
}
}
declare const axios: axios.AxiosStatic;
export = axios;