axios 1.16.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -0
- package/README.md +280 -245
- package/dist/axios.js +192 -72
- package/dist/axios.min.js +2 -2
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +215 -77
- package/dist/esm/axios.js +215 -77
- package/dist/esm/axios.min.js +2 -2
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +453 -190
- package/index.d.cts +9 -4
- package/index.d.ts +5 -2
- package/lib/adapters/fetch.js +85 -2
- package/lib/adapters/http.js +201 -147
- package/lib/adapters/xhr.js +2 -1
- package/lib/core/Axios.js +1 -0
- package/lib/core/AxiosHeaders.js +3 -35
- package/lib/defaults/transitional.js +1 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/Http2Sessions.js +119 -0
- package/lib/helpers/buildURL.js +1 -1
- package/lib/helpers/composeSignals.js +48 -47
- package/lib/helpers/formDataToJSON.js +1 -1
- package/lib/helpers/formDataToStream.js +2 -2
- package/lib/helpers/fromDataURI.js +18 -5
- package/lib/helpers/progressEventReducer.js +3 -0
- package/lib/helpers/resolveConfig.js +12 -6
- package/lib/helpers/sanitizeHeaderValue.js +60 -0
- package/lib/helpers/toFormData.js +1 -1
- package/lib/utils.js +31 -9
- package/package.json +31 -13
- package/dist/axios.js.map +0 -1
- package/dist/browser/axios.cjs.map +0 -1
- package/dist/esm/axios.js.map +0 -1
- package/dist/node/axios.cjs.map +0 -1
package/index.d.cts
CHANGED
|
@@ -66,7 +66,9 @@ declare class AxiosHeaders {
|
|
|
66
66
|
...targets: Array<AxiosHeaders | axios.RawAxiosHeaders | string | undefined | null>
|
|
67
67
|
): AxiosHeaders;
|
|
68
68
|
|
|
69
|
-
toJSON(asStrings
|
|
69
|
+
toJSON(asStrings: true): Record<string, string>;
|
|
70
|
+
toJSON(asStrings?: false): Record<string, string | string[]>;
|
|
71
|
+
toJSON(asStrings?: boolean): Record<string, string | string[]>;
|
|
70
72
|
|
|
71
73
|
static from(thing?: AxiosHeaders | axios.RawAxiosHeaders | string): AxiosHeaders;
|
|
72
74
|
|
|
@@ -162,7 +164,9 @@ declare class AxiosError<T = unknown, D = any> extends Error {
|
|
|
162
164
|
static readonly ETIMEDOUT = 'ETIMEDOUT';
|
|
163
165
|
}
|
|
164
166
|
|
|
165
|
-
declare class CanceledError<T> extends AxiosError<T> {
|
|
167
|
+
declare class CanceledError<T> extends AxiosError<T> {
|
|
168
|
+
readonly name: 'CanceledError';
|
|
169
|
+
}
|
|
166
170
|
|
|
167
171
|
declare class Axios {
|
|
168
172
|
constructor(config?: axios.AxiosRequestConfig);
|
|
@@ -392,6 +396,7 @@ declare namespace axios {
|
|
|
392
396
|
forcedJSONParsing?: boolean;
|
|
393
397
|
clarifyTimeoutError?: boolean;
|
|
394
398
|
legacyInterceptorReqResOrdering?: boolean;
|
|
399
|
+
advertiseZstdAcceptEncoding?: boolean;
|
|
395
400
|
}
|
|
396
401
|
|
|
397
402
|
interface GenericAbortSignal {
|
|
@@ -544,7 +549,7 @@ declare namespace axios {
|
|
|
544
549
|
| LookupAddress
|
|
545
550
|
>);
|
|
546
551
|
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
|
|
547
|
-
parseReviver?: (this: any, key: string, value: any, context?: { source
|
|
552
|
+
parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
|
|
548
553
|
fetchOptions?:
|
|
549
554
|
| Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'>
|
|
550
555
|
| Record<string, any>;
|
|
@@ -691,7 +696,7 @@ declare namespace axios {
|
|
|
691
696
|
CanceledError: typeof CanceledError;
|
|
692
697
|
HttpStatusCode: typeof HttpStatusCode;
|
|
693
698
|
readonly VERSION: string;
|
|
694
|
-
isCancel(value: any): value is
|
|
699
|
+
isCancel<T = any>(value: any): value is CanceledError<T>;
|
|
695
700
|
all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
|
696
701
|
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
|
697
702
|
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
package/index.d.ts
CHANGED
|
@@ -47,7 +47,9 @@ export class AxiosHeaders {
|
|
|
47
47
|
...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>
|
|
48
48
|
): AxiosHeaders;
|
|
49
49
|
|
|
50
|
-
toJSON(asStrings
|
|
50
|
+
toJSON(asStrings: true): Record<string, string>;
|
|
51
|
+
toJSON(asStrings?: false): Record<string, string | string[]>;
|
|
52
|
+
toJSON(asStrings?: boolean): Record<string, string | string[]>;
|
|
51
53
|
|
|
52
54
|
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
|
53
55
|
|
|
@@ -281,6 +283,7 @@ export interface TransitionalOptions {
|
|
|
281
283
|
forcedJSONParsing?: boolean;
|
|
282
284
|
clarifyTimeoutError?: boolean;
|
|
283
285
|
legacyInterceptorReqResOrdering?: boolean;
|
|
286
|
+
advertiseZstdAcceptEncoding?: boolean;
|
|
284
287
|
}
|
|
285
288
|
|
|
286
289
|
export interface GenericAbortSignal {
|
|
@@ -441,7 +444,7 @@ export interface AxiosRequestConfig<D = any> {
|
|
|
441
444
|
[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress
|
|
442
445
|
>);
|
|
443
446
|
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
|
|
444
|
-
parseReviver?: (this: any, key: string, value: any, context?: { source
|
|
447
|
+
parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
|
|
445
448
|
fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
|
|
446
449
|
httpVersion?: 1 | 2;
|
|
447
450
|
http2Options?: Record<string, any> & {
|
package/lib/adapters/fetch.js
CHANGED
|
@@ -13,11 +13,41 @@ import resolveConfig from '../helpers/resolveConfig.js';
|
|
|
13
13
|
import settle from '../core/settle.js';
|
|
14
14
|
import estimateDataURLDecodedBytes from '../helpers/estimateDataURLDecodedBytes.js';
|
|
15
15
|
import { VERSION } from '../env/data.js';
|
|
16
|
+
import { toByteStringHeaderObject } from '../helpers/sanitizeHeaderValue.js';
|
|
16
17
|
|
|
17
18
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
18
19
|
|
|
19
20
|
const { isFunction } = utils;
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
|
|
24
|
+
* This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} str The string to encode
|
|
27
|
+
*
|
|
28
|
+
* @returns {string} UTF-8 bytes as a Latin-1 string
|
|
29
|
+
*/
|
|
30
|
+
const encodeUTF8 = (str) =>
|
|
31
|
+
encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) =>
|
|
32
|
+
String.fromCharCode(parseInt(hex, 16))
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Node's WHATWG URL parser returns `username` and `password` percent-encoded.
|
|
36
|
+
// Decode before composing the `auth` option so credentials such as
|
|
37
|
+
// `my%40email.com:pass` are sent as `my@email.com:pass`. Falls back to the
|
|
38
|
+
// original value for malformed input so a bad encoding never throws.
|
|
39
|
+
const decodeURIComponentSafe = (value) => {
|
|
40
|
+
if (!utils.isString(value)) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
return decodeURIComponent(value);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
21
51
|
const test = (fn, ...args) => {
|
|
22
52
|
try {
|
|
23
53
|
return !!fn(...args);
|
|
@@ -26,8 +56,20 @@ const test = (fn, ...args) => {
|
|
|
26
56
|
}
|
|
27
57
|
};
|
|
28
58
|
|
|
59
|
+
const maybeWithAuthCredentials = (url) => {
|
|
60
|
+
const protocolIndex = url.indexOf('://');
|
|
61
|
+
let urlToCheck = url;
|
|
62
|
+
if (protocolIndex !== -1) {
|
|
63
|
+
urlToCheck = urlToCheck.slice(protocolIndex + 3);
|
|
64
|
+
}
|
|
65
|
+
return urlToCheck.includes('@') || urlToCheck.includes(':');
|
|
66
|
+
};
|
|
67
|
+
|
|
29
68
|
const factory = (env) => {
|
|
30
|
-
const globalObject =
|
|
69
|
+
const globalObject =
|
|
70
|
+
utils.global !== undefined && utils.global !== null
|
|
71
|
+
? utils.global
|
|
72
|
+
: globalThis;
|
|
31
73
|
const { ReadableStream, TextEncoder } = globalObject;
|
|
32
74
|
|
|
33
75
|
env = utils.merge.call(
|
|
@@ -170,6 +212,7 @@ const factory = (env) => {
|
|
|
170
212
|
|
|
171
213
|
const hasMaxContentLength = utils.isNumber(maxContentLength) && maxContentLength > -1;
|
|
172
214
|
const hasMaxBodyLength = utils.isNumber(maxBodyLength) && maxBodyLength > -1;
|
|
215
|
+
const own = (key) => (utils.hasOwnProp(config, key) ? config[key] : undefined);
|
|
173
216
|
|
|
174
217
|
let _fetch = envFetch || fetch;
|
|
175
218
|
|
|
@@ -192,6 +235,46 @@ const factory = (env) => {
|
|
|
192
235
|
let requestContentLength;
|
|
193
236
|
|
|
194
237
|
try {
|
|
238
|
+
// HTTP basic authentication
|
|
239
|
+
let auth = undefined;
|
|
240
|
+
const configAuth = own('auth');
|
|
241
|
+
|
|
242
|
+
if (configAuth) {
|
|
243
|
+
const username = configAuth.username || '';
|
|
244
|
+
const password = configAuth.password || '';
|
|
245
|
+
auth = {
|
|
246
|
+
username,
|
|
247
|
+
password
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (maybeWithAuthCredentials(url)) {
|
|
252
|
+
const parsedURL = new URL(url, platform.origin);
|
|
253
|
+
|
|
254
|
+
if (!auth && (parsedURL.username || parsedURL.password)) {
|
|
255
|
+
const urlUsername = decodeURIComponentSafe(parsedURL.username);
|
|
256
|
+
const urlPassword = decodeURIComponentSafe(parsedURL.password);
|
|
257
|
+
auth = {
|
|
258
|
+
username: urlUsername,
|
|
259
|
+
password: urlPassword
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (parsedURL.username || parsedURL.password) {
|
|
264
|
+
parsedURL.username = '';
|
|
265
|
+
parsedURL.password = '';
|
|
266
|
+
url = parsedURL.href;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (auth) {
|
|
271
|
+
headers.delete('authorization');
|
|
272
|
+
headers.set(
|
|
273
|
+
'Authorization',
|
|
274
|
+
'Basic ' + btoa(encodeUTF8((auth.username || '') + ':' + (auth.password || '')))
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
195
278
|
// Enforce maxContentLength for data: URLs up-front so we never materialize
|
|
196
279
|
// an oversized payload. The HTTP adapter applies the same check (see http.js
|
|
197
280
|
// "if (protocol === 'data:')" branch).
|
|
@@ -284,7 +367,7 @@ const factory = (env) => {
|
|
|
284
367
|
...fetchOptions,
|
|
285
368
|
signal: composedSignal,
|
|
286
369
|
method: method.toUpperCase(),
|
|
287
|
-
headers: headers.normalize()
|
|
370
|
+
headers: toByteStringHeaderObject(headers.normalize()),
|
|
288
371
|
body: data,
|
|
289
372
|
duplex: 'half',
|
|
290
373
|
credentials: isCredentialsSupported ? withCredentials : undefined,
|