axios 1.2.0 → 1.2.1
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.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +31 -0
- package/README.md +2 -3
- package/dist/axios.js +21 -4
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +28 -6
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +37 -14
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +25 -14
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +3 -0
- package/index.d.ts +13 -3
- package/index.js +4 -2
- package/lib/adapters/http.js +16 -8
- package/lib/adapters/xhr.js +2 -2
- package/lib/axios.js +3 -0
- package/lib/core/dispatchRequest.js +1 -1
- package/lib/env/data.js +1 -1
- package/lib/helpers/speedometer.js +1 -1
- package/lib/platform/browser/index.js +19 -0
- package/package.json +1 -1
package/index.d.cts
CHANGED
@@ -321,6 +321,8 @@ declare namespace axios {
|
|
321
321
|
serialize?: CustomParamsSerializer;
|
322
322
|
}
|
323
323
|
|
324
|
+
type BrowserProgressEvent = any;
|
325
|
+
|
324
326
|
interface AxiosProgressEvent {
|
325
327
|
loaded: number;
|
326
328
|
total?: number;
|
@@ -330,6 +332,7 @@ declare namespace axios {
|
|
330
332
|
estimated?: number;
|
331
333
|
upload?: boolean;
|
332
334
|
download?: boolean;
|
335
|
+
event?: BrowserProgressEvent;
|
333
336
|
}
|
334
337
|
|
335
338
|
interface AxiosRequestConfig<D = any> {
|
package/index.d.ts
CHANGED
@@ -6,7 +6,7 @@ type MethodsHeaders = {
|
|
6
6
|
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
7
7
|
};
|
8
8
|
|
9
|
-
interface CommonHeaders
|
9
|
+
interface CommonHeaders {
|
10
10
|
common: AxiosHeaders;
|
11
11
|
}
|
12
12
|
|
@@ -263,6 +263,8 @@ type MaxUploadRate = number;
|
|
263
263
|
|
264
264
|
type MaxDownloadRate = number;
|
265
265
|
|
266
|
+
type BrowserProgressEvent = any;
|
267
|
+
|
266
268
|
export interface AxiosProgressEvent {
|
267
269
|
loaded: number;
|
268
270
|
total?: number;
|
@@ -272,7 +274,7 @@ export interface AxiosProgressEvent {
|
|
272
274
|
estimated?: number;
|
273
275
|
upload?: boolean;
|
274
276
|
download?: boolean;
|
275
|
-
event?:
|
277
|
+
event?: BrowserProgressEvent;
|
276
278
|
}
|
277
279
|
|
278
280
|
type Milliseconds = number;
|
@@ -345,7 +347,7 @@ export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>
|
|
345
347
|
headers?: RawAxiosRequestHeaders | Partial<HeadersDefaults>;
|
346
348
|
}
|
347
349
|
|
348
|
-
export interface AxiosResponse<T = any, D = any>
|
350
|
+
export interface AxiosResponse<T = any, D = any> {
|
349
351
|
data: T;
|
350
352
|
status: number;
|
351
353
|
statusText: string;
|
@@ -371,6 +373,14 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|
371
373
|
status?: number;
|
372
374
|
toJSON: () => object;
|
373
375
|
cause?: Error;
|
376
|
+
static from<T = unknown, D = any>(
|
377
|
+
error: Error | unknown,
|
378
|
+
code?: string,
|
379
|
+
config?: AxiosRequestConfig<D>,
|
380
|
+
request?: any,
|
381
|
+
response?: AxiosResponse<T, D>,
|
382
|
+
customProps?: object,
|
383
|
+
): AxiosError<T, D>;
|
374
384
|
static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
375
385
|
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
376
386
|
static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
package/index.js
CHANGED
@@ -16,7 +16,8 @@ const {
|
|
16
16
|
spread,
|
17
17
|
toFormData,
|
18
18
|
AxiosHeaders,
|
19
|
-
formToJSON
|
19
|
+
formToJSON,
|
20
|
+
mergeConfig
|
20
21
|
} = axios;
|
21
22
|
|
22
23
|
export {
|
@@ -33,5 +34,6 @@ export {
|
|
33
34
|
spread,
|
34
35
|
toFormData,
|
35
36
|
AxiosHeaders,
|
36
|
-
formToJSON
|
37
|
+
formToJSON,
|
38
|
+
mergeConfig
|
37
39
|
}
|
package/lib/adapters/http.js
CHANGED
@@ -20,6 +20,11 @@ import AxiosHeaders from '../core/AxiosHeaders.js';
|
|
20
20
|
import AxiosTransformStream from '../helpers/AxiosTransformStream.js';
|
21
21
|
import EventEmitter from 'events';
|
22
22
|
|
23
|
+
const zlibOptions = {
|
24
|
+
flush: zlib.constants.Z_SYNC_FLUSH,
|
25
|
+
finishFlush: zlib.constants.Z_SYNC_FLUSH
|
26
|
+
}
|
27
|
+
|
23
28
|
const isBrotliSupported = utils.isFunction(zlib.createBrotliDecompress);
|
24
29
|
|
25
30
|
const {http: httpFollow, https: httpsFollow} = followRedirects;
|
@@ -262,7 +267,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
262
267
|
}
|
263
268
|
}
|
264
269
|
|
265
|
-
const contentLength =
|
270
|
+
const contentLength = utils.toFiniteNumber(headers.getContentLength());
|
266
271
|
|
267
272
|
if (utils.isArray(maxRate)) {
|
268
273
|
maxUploadRate = maxRate[0];
|
@@ -277,7 +282,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
277
282
|
}
|
278
283
|
|
279
284
|
data = stream.pipeline([data, new AxiosTransformStream({
|
280
|
-
length:
|
285
|
+
length: contentLength,
|
281
286
|
maxRate: utils.toFiniteNumber(maxUploadRate)
|
282
287
|
})], utils.noop);
|
283
288
|
|
@@ -320,7 +325,10 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
320
325
|
return reject(customErr);
|
321
326
|
}
|
322
327
|
|
323
|
-
headers.set(
|
328
|
+
headers.set(
|
329
|
+
'Accept-Encoding',
|
330
|
+
'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false
|
331
|
+
);
|
324
332
|
|
325
333
|
const options = {
|
326
334
|
path,
|
@@ -392,17 +400,17 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
392
400
|
streams.push(transformStream);
|
393
401
|
}
|
394
402
|
|
395
|
-
//
|
403
|
+
// decompress the response body transparently if required
|
396
404
|
let responseStream = res;
|
397
405
|
|
398
406
|
// return the last request in case of redirects
|
399
407
|
const lastRequest = res.req || req;
|
400
408
|
|
401
409
|
// if decompress disabled we should not decompress
|
402
|
-
if (config.decompress !== false) {
|
410
|
+
if (config.decompress !== false && res.headers['content-encoding']) {
|
403
411
|
// if no content, but headers still say that it is encoded,
|
404
412
|
// remove the header not confuse downstream operations
|
405
|
-
if (
|
413
|
+
if (method === 'HEAD' || res.statusCode === 204) {
|
406
414
|
delete res.headers['content-encoding'];
|
407
415
|
}
|
408
416
|
|
@@ -412,14 +420,14 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
412
420
|
case 'compress':
|
413
421
|
case 'deflate':
|
414
422
|
// add the unzipper to the body stream processing pipeline
|
415
|
-
streams.push(zlib.createUnzip());
|
423
|
+
streams.push(zlib.createUnzip(zlibOptions));
|
416
424
|
|
417
425
|
// remove the content-encoding in order to not confuse downstream operations
|
418
426
|
delete res.headers['content-encoding'];
|
419
427
|
break;
|
420
428
|
case 'br':
|
421
429
|
if (isBrotliSupported) {
|
422
|
-
streams.push(zlib.createBrotliDecompress());
|
430
|
+
streams.push(zlib.createBrotliDecompress(zlibOptions));
|
423
431
|
delete res.headers['content-encoding'];
|
424
432
|
}
|
425
433
|
}
|
package/lib/adapters/xhr.js
CHANGED
@@ -61,7 +61,7 @@ export default isXHRAdapterSupported && function (config) {
|
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
64
|
-
if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
|
64
|
+
if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
|
65
65
|
requestHeaders.setContentType(false); // Let the browser set it
|
66
66
|
}
|
67
67
|
|
@@ -89,7 +89,7 @@ export default isXHRAdapterSupported && function (config) {
|
|
89
89
|
const responseHeaders = AxiosHeaders.from(
|
90
90
|
'getAllResponseHeaders' in request && request.getAllResponseHeaders()
|
91
91
|
);
|
92
|
-
const responseData = !responseType || responseType === 'text' ||
|
92
|
+
const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
93
93
|
request.responseText : request.response;
|
94
94
|
const response = {
|
95
95
|
data: responseData,
|
package/lib/axios.js
CHANGED
@@ -70,6 +70,9 @@ axios.spread = spread;
|
|
70
70
|
// Expose isAxiosError
|
71
71
|
axios.isAxiosError = isAxiosError;
|
72
72
|
|
73
|
+
// Expose mergeConfig
|
74
|
+
axios.mergeConfig = mergeConfig;
|
75
|
+
|
73
76
|
axios.AxiosHeaders = AxiosHeaders;
|
74
77
|
|
75
78
|
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.2.
|
1
|
+
export const VERSION = "1.2.1";
|
@@ -31,6 +31,24 @@ const isStandardBrowserEnv = (() => {
|
|
31
31
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
32
32
|
})();
|
33
33
|
|
34
|
+
/**
|
35
|
+
* Determine if we're running in a standard browser webWorker environment
|
36
|
+
*
|
37
|
+
* Although the `isStandardBrowserEnv` method indicates that
|
38
|
+
* `allows axios to run in a web worker`, the WebWorker will still be
|
39
|
+
* filtered out due to its judgment standard
|
40
|
+
* `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
41
|
+
* This leads to a problem when axios post `FormData` in webWorker
|
42
|
+
*/
|
43
|
+
const isStandardBrowserWebWorkerEnv = (() => {
|
44
|
+
return (
|
45
|
+
typeof WorkerGlobalScope !== 'undefined' &&
|
46
|
+
self instanceof WorkerGlobalScope &&
|
47
|
+
typeof self.importScripts === 'function'
|
48
|
+
);
|
49
|
+
})();
|
50
|
+
|
51
|
+
|
34
52
|
export default {
|
35
53
|
isBrowser: true,
|
36
54
|
classes: {
|
@@ -39,5 +57,6 @@ export default {
|
|
39
57
|
Blob
|
40
58
|
},
|
41
59
|
isStandardBrowserEnv,
|
60
|
+
isStandardBrowserWebWorkerEnv,
|
42
61
|
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
43
62
|
};
|