axios 0.21.1 → 0.22.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 CHANGED
@@ -1,18 +1,126 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.22.0 (October 01, 2021)
4
+
5
+ Fixes and Functionality:
6
+ - Caseless header comparing in HTTP adapter ([#2880](https://github.com/axios/axios/pull/2880))
7
+ - Avoid package.json import fixing issues and warnings related to this ([#4041](https://github.com/axios/axios/pull/4041)), ([#4065](https://github.com/axios/axios/pull/4065))
8
+ - Fixed cancelToken leakage and added AbortController support ([#3305](https://github.com/axios/axios/pull/3305))
9
+ - Updating CI to run on release branches
10
+ - Bump follow redirects version
11
+ - Fixed default transitional config for custom Axios instance; ([#4052](https://github.com/axios/axios/pull/4052))
12
+
13
+ Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
14
+
15
+ - [Jay](mailto:jasonsaayman@gmail.com)
16
+ - [Matt R. Wilson](https://github.com/mastermatt)
17
+ - [Xianming Zhong](https://github.com/chinesedfan)
18
+ - [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
19
+
20
+ ### 0.21.4 (September 6, 2021)
21
+
22
+ Fixes and Functionality:
23
+ - Fixing JSON transform when data is stringified. Providing backward compatability and complying to the JSON RFC standard ([#4020](https://github.com/axios/axios/pull/4020))
24
+
25
+ Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
26
+
27
+ - [Jay](mailto:jasonsaayman@gmail.com)
28
+ - [Guillaume Fortaine](https://github.com/gfortaine)
29
+ - [Yusuke Kawasaki](https://github.com/kawanet)
30
+ - [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
31
+
32
+ ### 0.21.3 (September 4, 2021)
33
+
34
+ Fixes and Functionality:
35
+ - Fixing response interceptor not being called when request interceptor is attached ([#4013](https://github.com/axios/axios/pull/4013))
36
+
37
+ Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
38
+
39
+ - [Jay](mailto:jasonsaayman@gmail.com)
40
+ - [Julian Hollmann](https://github.com/nerdbeere)
41
+
42
+ ### 0.21.2 (September 4, 2021)
43
+
44
+ Fixes and Functionality:
45
+
46
+ - Updating axios requests to be delayed by pre-emptive promise creation ([#2702](https://github.com/axios/axios/pull/2702))
47
+ - Adding "synchronous" and "runWhen" options to interceptors api ([#2702](https://github.com/axios/axios/pull/2702))
48
+ - Updating of transformResponse ([#3377](https://github.com/axios/axios/pull/3377))
49
+ - Adding ability to omit User-Agent header ([#3703](https://github.com/axios/axios/pull/3703))
50
+ - Adding multiple JSON improvements ([#3688](https://github.com/axios/axios/pull/3688), [#3763](https://github.com/axios/axios/pull/3763))
51
+ - Fixing quadratic runtime and extra memory usage when setting a maxContentLength ([#3738](https://github.com/axios/axios/pull/3738))
52
+ - Adding parseInt to config.timeout ([#3781](https://github.com/axios/axios/pull/3781))
53
+ - Adding custom return type support to interceptor ([#3783](https://github.com/axios/axios/pull/3783))
54
+ - Adding security fix for ReDoS vulnerability ([#3980](https://github.com/axios/axios/pull/3980))
55
+
56
+ Internal and Tests:
57
+
58
+ - Updating build dev dependancies ([#3401](https://github.com/axios/axios/pull/3401))
59
+ - Fixing builds running on Travis CI ([#3538](https://github.com/axios/axios/pull/3538))
60
+ - Updating follow rediect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
61
+ - Updating karma sauce launcher to fix failing sauce tests ([#3712](https://github.com/axios/axios/pull/3712), [#3717](https://github.com/axios/axios/pull/3717))
62
+ - Updating content-type header for application/json to not contain charset field, according do RFC 8259 ([#2154](https://github.com/axios/axios/pull/2154))
63
+ - Fixing tests by bumping karma-sauce-launcher version ([#3813](https://github.com/axios/axios/pull/3813))
64
+ - Changing testing process from Travis CI to GitHub Actions ([#3938](https://github.com/axios/axios/pull/3938))
65
+
66
+ Documentation:
67
+
68
+ - Updating documentation around the use of `AUTH_TOKEN` with multiple domain endpoints ([#3539](https://github.com/axios/axios/pull/3539))
69
+ - Remove duplication of item in changelog ([#3523](https://github.com/axios/axios/pull/3523))
70
+ - Fixing gramatical errors ([#2642](https://github.com/axios/axios/pull/2642))
71
+ - Fixing spelling error ([#3567](https://github.com/axios/axios/pull/3567))
72
+ - Moving gitpod metion ([#2637](https://github.com/axios/axios/pull/2637))
73
+ - Adding new axios documentation website link ([#3681](https://github.com/axios/axios/pull/3681), [#3707](https://github.com/axios/axios/pull/3707))
74
+ - Updating documentation around dispatching requests ([#3772](https://github.com/axios/axios/pull/3772))
75
+ - Adding documentation for the type guard isAxiosError ([#3767](https://github.com/axios/axios/pull/3767))
76
+ - Adding explanation of cancel token ([#3803](https://github.com/axios/axios/pull/3803))
77
+ - Updating CI status badge ([#3953](https://github.com/axios/axios/pull/3953))
78
+ - Fixing errors with JSON documentation ([#3936](https://github.com/axios/axios/pull/3936))
79
+ - Fixing README typo under Request Config ([#3825](https://github.com/axios/axios/pull/3825))
80
+ - Adding axios-multi-api to the ecosystem file ([#3817](https://github.com/axios/axios/pull/3817))
81
+ - Adding SECURITY.md to properly disclose security vulnerabilities ([#3981](https://github.com/axios/axios/pull/3981))
82
+
83
+ Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
84
+
85
+ - [Jay](mailto:jasonsaayman@gmail.com)
86
+ - [Sasha Korotkov](https://github.com/SashaKoro)
87
+ - [Daniel Lopretto](https://github.com/timemachine3030)
88
+ - [Mike Bishop](https://github.com/MikeBishop)
89
+ - [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
90
+ - [Mark](https://github.com/bimbiltu)
91
+ - [Philipe Gouveia Paixão](https://github.com/piiih)
92
+ - [hippo](https://github.com/hippo2cat)
93
+ - [ready-research](https://github.com/ready-research)
94
+ - [Xianming Zhong](https://github.com/chinesedfan)
95
+ - [Christopher Chrapka](https://github.com/OJezu)
96
+ - [Brian Anglin](https://github.com/anglinb)
97
+ - [Kohta Ito](https://github.com/koh110)
98
+ - [Ali Clark](https://github.com/aliclark)
99
+ - [caikan](https://github.com/caikan)
100
+ - [Elina Gorshkova](https://github.com/elinagorshkova)
101
+ - [Ryota Ikezawa](https://github.com/paveg)
102
+ - [Nisar Hassan Naqvi](https://github.com/nisarhassan12)
103
+ - [Jake](https://github.com/codemaster138)
104
+ - [TagawaHirotaka](https://github.com/wafuwafu13)
105
+ - [Johannes Jarbratt](https://github.com/johachi)
106
+ - [Mo Sattler](https://github.com/MoSattler)
107
+ - [Sam Carlton](https://github.com/ThatGuySam)
108
+ - [Matt Czapliński](https://github.com/MattCCC)
109
+ - [Ziding Zhang](https://github.com/zidingz)
110
+
3
111
  ### 0.21.1 (December 21, 2020)
4
112
 
5
113
  Fixes and Functionality:
6
114
 
7
- - Hotfix: Prevent SSRF (#3410)
8
- - Protocol not parsed when setting proxy config from env vars (#3070)
9
- - Updating axios in types to be lower case (#2797)
10
- - Adding a type guard for `AxiosError` (#2949)
115
+ - Hotfix: Prevent SSRF ([#3410](https://github.com/axios/axios/pull/3410))
116
+ - Protocol not parsed when setting proxy config from env vars ([#3070](https://github.com/axios/axios/pull/3070))
117
+ - Updating axios in types to be lower case ([#2797](https://github.com/axios/axios/pull/2797))
118
+ - Adding a type guard for `AxiosError` ([#2949](https://github.com/axios/axios/pull/2949))
11
119
 
12
120
  Internal and Tests:
13
121
 
14
- - Remove the skipping of the `socket` http test (#3364)
15
- - Use different socket for Win32 test (#3375)
122
+ - Remove the skipping of the `socket` http test ([#3364](https://github.com/axios/axios/pull/3364))
123
+ - Use different socket for Win32 test ([#3375](https://github.com/axios/axios/pull/3375))
16
124
 
17
125
  Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
18
126
 
@@ -93,7 +201,7 @@ Fixes and Functionality:
93
201
  - Adding test to check if password with non-Latin1 characters pass
94
202
  - Fixing 'Network Error' in react native android ([#1487](https://github.com/axios/axios/pull/1487))
95
203
  There is a bug in react native Android platform when using get method. It will trigger a 'Network Error' when passing the requestData which is an empty string to request.send function. So if the requestData is an empty string we can set it to null as well to fix the bug.
96
- - Fixing Cookie Helper with Asyc Components ([#1105](https://github.com/axios/axios/pull/1105)) ([#1107](https://github.com/axios/axios/pull/1107))
204
+ - Fixing Cookie Helper with Async Components ([#1105](https://github.com/axios/axios/pull/1105)) ([#1107](https://github.com/axios/axios/pull/1107))
97
205
  - Fixing 'progressEvent' type ([#2851](https://github.com/axios/axios/pull/2851))
98
206
  - Fix 'progressEvent' type
99
207
  - Update axios.ts
@@ -305,7 +413,6 @@ Fixes and Functionality:
305
413
  - Fixing set `config.method` after mergeConfig for Axios.prototype.request ([#2383](https://github.com/axios/axios/pull/2383))
306
414
  - Axios create url bug ([#2290](https://github.com/axios/axios/pull/2290))
307
415
  - Do not modify config.url when using a relative baseURL (resolves [#1628](https://github.com/axios/axios/issues/1098)) ([#2391](https://github.com/axios/axios/pull/2391))
308
- - Add typescript HTTP method definition for LINK and UNLINK ([#2444](https://github.com/axios/axios/pull/2444))
309
416
 
310
417
  Internal:
311
418
 
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
4
4
  [![CDNJS](https://img.shields.io/cdnjs/v/axios.svg?style=flat-square)](https://cdnjs.com/libraries/axios)
5
- [![build status](https://img.shields.io/travis/axios/axios/master.svg?style=flat-square)](https://travis-ci.org/axios/axios)
5
+ ![Build status](https://github.com/axios/axios/actions/workflows/ci.yml/badge.svg)
6
+ [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/axios/axios)
6
7
  [![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
7
8
  [![install size](https://packagephobia.now.sh/badge?p=axios)](https://packagephobia.now.sh/result?p=axios)
8
9
  [![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](http://npm-stat.com/charts.html?package=axios)
@@ -10,6 +11,9 @@
10
11
  [![code helpers](https://www.codetriage.com/axios/axios/badges/users.svg)](https://www.codetriage.com/axios/axios)
11
12
 
12
13
  Promise based HTTP client for the browser and node.js
14
+
15
+ > New axios docs website: [click here](https://axios-http.com/)
16
+
13
17
  ## Table of Contents
14
18
 
15
19
  - [Features](#features)
@@ -448,12 +452,36 @@ These are the available config options for making requests. Only the `url` is re
448
452
  cancelToken: new CancelToken(function (cancel) {
449
453
  }),
450
454
 
455
+ // an alternative way to cancel Axios requests using AbortController
456
+ signal: new AbortController().signal,
457
+
451
458
  // `decompress` indicates whether or not the response body should be decompressed
452
459
  // automatically. If set to `true` will also remove the 'content-encoding' header
453
460
  // from the responses objects of all decompressed responses
454
461
  // - Node only (XHR cannot turn off decompression)
455
462
  decompress: true // default
456
463
 
464
+ // `insecureHTTPParser` boolean.
465
+ // Indicates where to use an insecure HTTP parser that accepts invalid HTTP headers.
466
+ // This may allow interoperability with non-conformant HTTP implementations.
467
+ // Using the insecure parser should be avoided.
468
+ // see options https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_http_request_url_options_callback
469
+ // see also https://nodejs.org/en/blog/vulnerability/february-2020-security-releases/#strict-http-header-parsing-none
470
+ insecureHTTPParser: undefined // default
471
+
472
+ // transitional options for backward compatibility that may be removed in the newer versions
473
+ transitional: {
474
+ // silent JSON parsing mode
475
+ // `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
476
+ // `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
477
+ silentJSONParsing: true, // default value for the current Axios version
478
+
479
+ // try to parse the response string as JSON even if `responseType` is not 'json'
480
+ forcedJSONParsing: true,
481
+
482
+ // throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
483
+ clarifyTimeoutError: false,
484
+ }
457
485
  }
458
486
  ```
459
487
 
@@ -510,7 +538,11 @@ You can specify config defaults that will be applied to every request.
510
538
 
511
539
  ```js
512
540
  axios.defaults.baseURL = 'https://api.example.com';
541
+
542
+ // Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them.
543
+ // See below for an example using Custom instance defaults instead.
513
544
  axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
545
+
514
546
  axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
515
547
  ```
516
548
 
@@ -585,6 +617,34 @@ const instance = axios.create();
585
617
  instance.interceptors.request.use(function () {/*...*/});
586
618
  ```
587
619
 
620
+ When you add request interceptors, they are presumed to be asynchronous by default. This can cause a delay
621
+ in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
622
+ the interceptor and your request gets put on the bottom of the call stack). If your request interceptors are synchronous you can add a flag
623
+ to the options object that will tell axios to run the code synchronously and avoid any delays in request execution.
624
+
625
+ ```js
626
+ axios.interceptors.request.use(function (config) {
627
+ config.headers.test = 'I am only a header!';
628
+ return config;
629
+ }, null, { synchronous: true });
630
+ ```
631
+
632
+ If you want to execute a particular interceptor based on a runtime check,
633
+ you can add a `runWhen` function to the options object. The interceptor will not be executed **if and only if** the return
634
+ of `runWhen` is `false`. The function will be called with the config
635
+ object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
636
+ asynchronous request interceptor that only needs to run at certain times.
637
+
638
+ ```js
639
+ function onGetCall(config) {
640
+ return config.method === 'get';
641
+ }
642
+ axios.interceptors.request.use(function (config) {
643
+ config.headers.test = 'special get headers';
644
+ return config;
645
+ }, null, { runWhen: onGetCall });
646
+ ```
647
+
588
648
  ## Handling Errors
589
649
 
590
650
  ```js
@@ -677,7 +737,21 @@ axios.get('/user/12345', {
677
737
  cancel();
678
738
  ```
679
739
 
680
- > Note: you can cancel several requests with the same cancel token.
740
+ Axios supports AbortController to abort requests in [`fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch) way:
741
+ ```js
742
+ const controller = new AbortController();
743
+
744
+ axios.get('/foo/bar', {
745
+ signal: controller.signal
746
+ }).then(function(response) {
747
+ //...
748
+ });
749
+ // cancel the request
750
+ controller.abort()
751
+ ```
752
+
753
+ > Note: you can cancel several requests with the same cancel token/abort controller.
754
+ > If a cancellation token is already cancelled at the moment of starting an Axios request, then the request is cancelled immediately, without any attempts to make real request.
681
755
 
682
756
  ## Using application/x-www-form-urlencoded format
683
757
 
@@ -777,12 +851,30 @@ axios depends on a native ES6 Promise implementation to be [supported](http://ca
777
851
  If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
778
852
 
779
853
  ## TypeScript
780
- axios includes [TypeScript](http://typescriptlang.org) definitions.
854
+
855
+ axios includes [TypeScript](http://typescriptlang.org) definitions and a type guard for axios errors.
856
+
781
857
  ```typescript
782
- import axios from 'axios';
783
- axios.get('/user?ID=12345');
858
+ let user: User = null;
859
+ try {
860
+ const { data } = await axios.get('/user?ID=12345');
861
+ user = data.userDetails;
862
+ } catch (error) {
863
+ if (axios.isAxiosError(error)) {
864
+ handleAxiosError(error);
865
+ } else {
866
+ handleUnexpectedError(error);
867
+ }
868
+ }
784
869
  ```
785
870
 
871
+ ## Online one-click setup
872
+
873
+ You can use Gitpod an online IDE(which is free for Open Source) for contributing or running the examples online.
874
+
875
+ [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/axios/axios/blob/master/examples/server.js)
876
+
877
+
786
878
  ## Resources
787
879
 
788
880
  * [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security Policy
2
+
3
+ ## Reporting a Vulnerability
4
+
5
+ Please report security issues to jasonsaayman@gmail.com