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/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?: ProgressEvent;
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
  }
@@ -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 = +headers.getContentLength();
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: utils.toFiniteNumber(contentLength),
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('Accept-Encoding', 'gzip, deflate, br', false);
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
- // uncompress the response body transparently if required
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 ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
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
  }
@@ -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' || responseType === 'json' ?
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);
@@ -20,7 +20,7 @@ function throwIfCancellationRequested(config) {
20
20
  }
21
21
 
22
22
  if (config.signal && config.signal.aborted) {
23
- throw new CanceledError();
23
+ throw new CanceledError(null, config);
24
24
  }
25
25
  }
26
26
 
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.2.0";
1
+ export const VERSION = "1.2.1";
@@ -48,7 +48,7 @@ function speedometer(samplesCount, min) {
48
48
 
49
49
  const passed = startedAt && now - startedAt;
50
50
 
51
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
51
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
52
52
  };
53
53
  }
54
54
 
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {