axios 0.21.0 → 0.21.4
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 +115 -2
- package/README.md +77 -7
- package/SECURITY.md +5 -0
- package/dist/axios.js +2031 -1574
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -2
- package/dist/axios.min.map +1 -1
- package/index.d.ts +11 -3
- package/lib/adapters/http.js +61 -17
- package/lib/adapters/xhr.js +35 -25
- package/lib/axios.js +3 -0
- package/lib/core/Axios.js +60 -7
- package/lib/core/InterceptorManager.js +4 -2
- package/lib/core/README.md +1 -0
- package/lib/core/dispatchRequest.js +6 -3
- package/lib/core/transformData.js +3 -1
- package/lib/defaults.js +43 -7
- package/lib/helpers/isAxiosError.js +11 -0
- package/lib/helpers/validator.js +105 -0
- package/lib/utils.js +1 -3
- package/package.json +19 -21
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,119 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 0.21.4 (September 6, 2021)
|
4
|
+
|
5
|
+
Fixes and Functionality:
|
6
|
+
- Fixing JSON transform when data is stringified. Providing backward compatibility and complying to the JSON RFC standard ([#4020](https://github.com/axios/axios/pull/4020))
|
7
|
+
|
8
|
+
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
9
|
+
|
10
|
+
- [Jay](mailto:jasonsaayman@gmail.com)
|
11
|
+
- [Guillaume Fortaine](https://github.com/gfortaine)
|
12
|
+
- [Yusuke Kawasaki](https://github.com/kawanet)
|
13
|
+
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
14
|
+
|
15
|
+
### 0.21.3 (September 4, 2021)
|
16
|
+
|
17
|
+
Fixes and Functionality:
|
18
|
+
- Fixing response interceptor not being called when request interceptor is attached ([#4013](https://github.com/axios/axios/pull/4013))
|
19
|
+
|
20
|
+
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
21
|
+
|
22
|
+
- [Jay](mailto:jasonsaayman@gmail.com)
|
23
|
+
- [Julian Hollmann](https://github.com/nerdbeere)
|
24
|
+
|
25
|
+
### 0.21.2 (September 4, 2021)
|
26
|
+
|
27
|
+
Fixes and Functionality:
|
28
|
+
|
29
|
+
- Updating axios requests to be delayed by pre-emptive promise creation ([#2702](https://github.com/axios/axios/pull/2702))
|
30
|
+
- Adding "synchronous" and "runWhen" options to interceptors api ([#2702](https://github.com/axios/axios/pull/2702))
|
31
|
+
- Updating of transformResponse ([#3377](https://github.com/axios/axios/pull/3377))
|
32
|
+
- Adding ability to omit User-Agent header ([#3703](https://github.com/axios/axios/pull/3703))
|
33
|
+
- Adding multiple JSON improvements ([#3688](https://github.com/axios/axios/pull/3688), [#3763](https://github.com/axios/axios/pull/3763))
|
34
|
+
- Fixing quadratic runtime and extra memory usage when setting a maxContentLength ([#3738](https://github.com/axios/axios/pull/3738))
|
35
|
+
- Adding parseInt to config.timeout ([#3781](https://github.com/axios/axios/pull/3781))
|
36
|
+
- Adding custom return type support to interceptor ([#3783](https://github.com/axios/axios/pull/3783))
|
37
|
+
- Adding security fix for ReDoS vulnerability ([#3980](https://github.com/axios/axios/pull/3980))
|
38
|
+
|
39
|
+
Internal and Tests:
|
40
|
+
|
41
|
+
- Updating build dev dependancies ([#3401](https://github.com/axios/axios/pull/3401))
|
42
|
+
- Fixing builds running on Travis CI ([#3538](https://github.com/axios/axios/pull/3538))
|
43
|
+
- Updating follow rediect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
|
44
|
+
- 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))
|
45
|
+
- Updating content-type header for application/json to not contain charset field, according do RFC 8259 ([#2154](https://github.com/axios/axios/pull/2154))
|
46
|
+
- Fixing tests by bumping karma-sauce-launcher version ([#3813](https://github.com/axios/axios/pull/3813))
|
47
|
+
- Changing testing process from Travis CI to GitHub Actions ([#3938](https://github.com/axios/axios/pull/3938))
|
48
|
+
|
49
|
+
Documentation:
|
50
|
+
|
51
|
+
- Updating documentation around the use of `AUTH_TOKEN` with multiple domain endpoints ([#3539](https://github.com/axios/axios/pull/3539))
|
52
|
+
- Remove duplication of item in changelog ([#3523](https://github.com/axios/axios/pull/3523))
|
53
|
+
- Fixing gramatical errors ([#2642](https://github.com/axios/axios/pull/2642))
|
54
|
+
- Fixing spelling error ([#3567](https://github.com/axios/axios/pull/3567))
|
55
|
+
- Moving gitpod metion ([#2637](https://github.com/axios/axios/pull/2637))
|
56
|
+
- Adding new axios documentation website link ([#3681](https://github.com/axios/axios/pull/3681), [#3707](https://github.com/axios/axios/pull/3707))
|
57
|
+
- Updating documentation around dispatching requests ([#3772](https://github.com/axios/axios/pull/3772))
|
58
|
+
- Adding documentation for the type guard isAxiosError ([#3767](https://github.com/axios/axios/pull/3767))
|
59
|
+
- Adding explanation of cancel token ([#3803](https://github.com/axios/axios/pull/3803))
|
60
|
+
- Updating CI status badge ([#3953](https://github.com/axios/axios/pull/3953))
|
61
|
+
- Fixing errors with JSON documentation ([#3936](https://github.com/axios/axios/pull/3936))
|
62
|
+
- Fixing README typo under Request Config ([#3825](https://github.com/axios/axios/pull/3825))
|
63
|
+
- Adding axios-multi-api to the ecosystem file ([#3817](https://github.com/axios/axios/pull/3817))
|
64
|
+
- Adding SECURITY.md to properly disclose security vulnerabilities ([#3981](https://github.com/axios/axios/pull/3981))
|
65
|
+
|
66
|
+
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
67
|
+
|
68
|
+
- [Jay](mailto:jasonsaayman@gmail.com)
|
69
|
+
- [Sasha Korotkov](https://github.com/SashaKoro)
|
70
|
+
- [Daniel Lopretto](https://github.com/timemachine3030)
|
71
|
+
- [Mike Bishop](https://github.com/MikeBishop)
|
72
|
+
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
73
|
+
- [Mark](https://github.com/bimbiltu)
|
74
|
+
- [Philipe Gouveia Paixão](https://github.com/piiih)
|
75
|
+
- [hippo](https://github.com/hippo2cat)
|
76
|
+
- [ready-research](https://github.com/ready-research)
|
77
|
+
- [Xianming Zhong](https://github.com/chinesedfan)
|
78
|
+
- [Christopher Chrapka](https://github.com/OJezu)
|
79
|
+
- [Brian Anglin](https://github.com/anglinb)
|
80
|
+
- [Kohta Ito](https://github.com/koh110)
|
81
|
+
- [Ali Clark](https://github.com/aliclark)
|
82
|
+
- [caikan](https://github.com/caikan)
|
83
|
+
- [Elina Gorshkova](https://github.com/elinagorshkova)
|
84
|
+
- [Ryota Ikezawa](https://github.com/paveg)
|
85
|
+
- [Nisar Hassan Naqvi](https://github.com/nisarhassan12)
|
86
|
+
- [Jake](https://github.com/codemaster138)
|
87
|
+
- [TagawaHirotaka](https://github.com/wafuwafu13)
|
88
|
+
- [Johannes Jarbratt](https://github.com/johachi)
|
89
|
+
- [Mo Sattler](https://github.com/MoSattler)
|
90
|
+
- [Sam Carlton](https://github.com/ThatGuySam)
|
91
|
+
- [Matt Czapliński](https://github.com/MattCCC)
|
92
|
+
- [Ziding Zhang](https://github.com/zidingz)
|
93
|
+
|
94
|
+
### 0.21.1 (December 21, 2020)
|
95
|
+
|
96
|
+
Fixes and Functionality:
|
97
|
+
|
98
|
+
- Hotfix: Prevent SSRF ([#3410](https://github.com/axios/axios/pull/3410))
|
99
|
+
- Protocol not parsed when setting proxy config from env vars ([#3070](https://github.com/axios/axios/pull/3070))
|
100
|
+
- Updating axios in types to be lower case ([#2797](https://github.com/axios/axios/pull/2797))
|
101
|
+
- Adding a type guard for `AxiosError` ([#2949](https://github.com/axios/axios/pull/2949))
|
102
|
+
|
103
|
+
Internal and Tests:
|
104
|
+
|
105
|
+
- Remove the skipping of the `socket` http test ([#3364](https://github.com/axios/axios/pull/3364))
|
106
|
+
- Use different socket for Win32 test ([#3375](https://github.com/axios/axios/pull/3375))
|
107
|
+
|
108
|
+
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
109
|
+
|
110
|
+
- Daniel Lopretto <timemachine3030@users.noreply.github.com>
|
111
|
+
- Jason Kwok <JasonHK@users.noreply.github.com>
|
112
|
+
- Jay <jasonsaayman@gmail.com>
|
113
|
+
- Jonathan Foster <jonathan@jonathanfoster.io>
|
114
|
+
- Remco Haszing <remcohaszing@gmail.com>
|
115
|
+
- Xianming Zhong <chinesedfan@qq.com>
|
116
|
+
|
3
117
|
### 0.21.0 (October 23, 2020)
|
4
118
|
|
5
119
|
Fixes and Functionality:
|
@@ -70,7 +184,7 @@ Fixes and Functionality:
|
|
70
184
|
- Adding test to check if password with non-Latin1 characters pass
|
71
185
|
- Fixing 'Network Error' in react native android ([#1487](https://github.com/axios/axios/pull/1487))
|
72
186
|
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.
|
73
|
-
- Fixing Cookie Helper with
|
187
|
+
- Fixing Cookie Helper with Async Components ([#1105](https://github.com/axios/axios/pull/1105)) ([#1107](https://github.com/axios/axios/pull/1107))
|
74
188
|
- Fixing 'progressEvent' type ([#2851](https://github.com/axios/axios/pull/2851))
|
75
189
|
- Fix 'progressEvent' type
|
76
190
|
- Update axios.ts
|
@@ -282,7 +396,6 @@ Fixes and Functionality:
|
|
282
396
|
- Fixing set `config.method` after mergeConfig for Axios.prototype.request ([#2383](https://github.com/axios/axios/pull/2383))
|
283
397
|
- Axios create url bug ([#2290](https://github.com/axios/axios/pull/2290))
|
284
398
|
- 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))
|
285
|
-
- Add typescript HTTP method definition for LINK and UNLINK ([#2444](https://github.com/axios/axios/pull/2444))
|
286
399
|
|
287
400
|
Internal:
|
288
401
|
|
package/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
[](https://www.npmjs.org/package/axios)
|
4
4
|
[](https://cdnjs.com/libraries/axios)
|
5
|
-
|
5
|
+

|
6
|
+
[](https://gitpod.io/#https://github.com/axios/axios)
|
6
7
|
[](https://coveralls.io/r/mzabriskie/axios)
|
7
8
|
[](https://packagephobia.now.sh/result?p=axios)
|
8
9
|
[](http://npm-stat.com/charts.html?package=axios)
|
@@ -10,6 +11,9 @@
|
|
10
11
|
[](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)
|
@@ -422,7 +426,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
422
426
|
httpAgent: new http.Agent({ keepAlive: true }),
|
423
427
|
httpsAgent: new https.Agent({ keepAlive: true }),
|
424
428
|
|
425
|
-
// `proxy` defines the hostname and
|
429
|
+
// `proxy` defines the hostname, port, and protocol of the proxy server.
|
426
430
|
// You can also define your proxy using the conventional `http_proxy` and
|
427
431
|
// `https_proxy` environment variables. If you are using environment variables
|
428
432
|
// for your proxy configuration, you can also define a `no_proxy` environment
|
@@ -432,7 +436,9 @@ These are the available config options for making requests. Only the `url` is re
|
|
432
436
|
// supplies credentials.
|
433
437
|
// This will set an `Proxy-Authorization` header, overwriting any existing
|
434
438
|
// `Proxy-Authorization` custom headers you have set using `headers`.
|
439
|
+
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
435
440
|
proxy: {
|
441
|
+
protocol: 'https',
|
436
442
|
host: '127.0.0.1',
|
437
443
|
port: 9000,
|
438
444
|
auth: {
|
@@ -450,8 +456,21 @@ These are the available config options for making requests. Only the `url` is re
|
|
450
456
|
// automatically. If set to `true` will also remove the 'content-encoding' header
|
451
457
|
// from the responses objects of all decompressed responses
|
452
458
|
// - Node only (XHR cannot turn off decompression)
|
453
|
-
decompress: true // default
|
454
|
-
|
459
|
+
decompress: true, // default
|
460
|
+
|
461
|
+
// transitional options for backward compatibility that may be removed in the newer versions
|
462
|
+
transitional: {
|
463
|
+
// silent JSON parsing mode
|
464
|
+
// `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
|
465
|
+
// `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
|
466
|
+
silentJSONParsing: true, // default value for the current Axios version
|
467
|
+
|
468
|
+
// try to parse the response string as JSON even if `responseType` is not 'json'
|
469
|
+
forcedJSONParsing: true,
|
470
|
+
|
471
|
+
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
472
|
+
clarifyTimeoutError: false,
|
473
|
+
}
|
455
474
|
}
|
456
475
|
```
|
457
476
|
|
@@ -508,7 +527,11 @@ You can specify config defaults that will be applied to every request.
|
|
508
527
|
|
509
528
|
```js
|
510
529
|
axios.defaults.baseURL = 'https://api.example.com';
|
530
|
+
|
531
|
+
// Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them.
|
532
|
+
// See below for an example using Custom instance defaults instead.
|
511
533
|
axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
|
534
|
+
|
512
535
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
|
513
536
|
```
|
514
537
|
|
@@ -583,6 +606,34 @@ const instance = axios.create();
|
|
583
606
|
instance.interceptors.request.use(function () {/*...*/});
|
584
607
|
```
|
585
608
|
|
609
|
+
When you add request interceptors, they are presumed to be asynchronous by default. This can cause a delay
|
610
|
+
in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
|
611
|
+
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
|
612
|
+
to the options object that will tell axios to run the code synchronously and avoid any delays in request execution.
|
613
|
+
|
614
|
+
```js
|
615
|
+
axios.interceptors.request.use(function (config) {
|
616
|
+
config.headers.test = 'I am only a header!';
|
617
|
+
return config;
|
618
|
+
}, null, { synchronous: true });
|
619
|
+
```
|
620
|
+
|
621
|
+
If you want to execute a particular interceptor based on a runtime check,
|
622
|
+
you can add a `runWhen` function to the options object. The interceptor will not be executed **if and only if** the return
|
623
|
+
of `runWhen` is `false`. The function will be called with the config
|
624
|
+
object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
|
625
|
+
asynchronous request interceptor that only needs to run at certain times.
|
626
|
+
|
627
|
+
```js
|
628
|
+
function onGetCall(config) {
|
629
|
+
return config.method === 'get';
|
630
|
+
}
|
631
|
+
axios.interceptors.request.use(function (config) {
|
632
|
+
config.headers.test = 'special get headers';
|
633
|
+
return config;
|
634
|
+
}, null, { runWhen: onGetCall });
|
635
|
+
```
|
636
|
+
|
586
637
|
## Handling Errors
|
587
638
|
|
588
639
|
```js
|
@@ -676,6 +727,7 @@ cancel();
|
|
676
727
|
```
|
677
728
|
|
678
729
|
> Note: you can cancel several requests with the same cancel token.
|
730
|
+
> 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.
|
679
731
|
|
680
732
|
## Using application/x-www-form-urlencoded format
|
681
733
|
|
@@ -775,12 +827,30 @@ axios depends on a native ES6 Promise implementation to be [supported](http://ca
|
|
775
827
|
If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
|
776
828
|
|
777
829
|
## TypeScript
|
778
|
-
|
830
|
+
|
831
|
+
axios includes [TypeScript](http://typescriptlang.org) definitions and a type guard for axios errors.
|
832
|
+
|
779
833
|
```typescript
|
780
|
-
|
781
|
-
|
834
|
+
let user: User = null;
|
835
|
+
try {
|
836
|
+
const { data } = await axios.get('/user?ID=12345');
|
837
|
+
user = data.userDetails;
|
838
|
+
} catch (error) {
|
839
|
+
if (axios.isAxiosError(error)) {
|
840
|
+
handleAxiosError(error);
|
841
|
+
} else {
|
842
|
+
handleUnexpectedError(error);
|
843
|
+
}
|
844
|
+
}
|
782
845
|
```
|
783
846
|
|
847
|
+
## Online one-click setup
|
848
|
+
|
849
|
+
You can use Gitpod an online IDE(which is free for Open Source) for contributing or running the examples online.
|
850
|
+
|
851
|
+
[](https://gitpod.io/#https://github.com/axios/axios/blob/master/examples/server.js)
|
852
|
+
|
853
|
+
|
784
854
|
## Resources
|
785
855
|
|
786
856
|
* [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
|