axios 0.26.1 → 0.27.2
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 +49 -12
- package/README.md +114 -32
- package/dist/axios.js +479 -177
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -1
- package/dist/axios.min.map +1 -1
- package/index.d.ts +37 -4
- package/lib/adapters/http.js +47 -27
- package/lib/adapters/xhr.js +18 -8
- package/lib/axios.js +8 -1
- package/lib/cancel/CancelToken.js +3 -3
- package/lib/cancel/CanceledError.js +22 -0
- package/lib/core/Axios.js +20 -8
- package/lib/core/AxiosError.js +86 -0
- package/lib/core/dispatchRequest.js +3 -3
- package/lib/core/mergeConfig.js +1 -0
- package/lib/core/settle.js +3 -3
- package/lib/defaults/env/FormData.js +2 -0
- package/lib/defaults/index.js +18 -3
- package/lib/env/data.js +1 -1
- package/lib/helpers/null.js +2 -0
- package/lib/helpers/parseProtocol.js +6 -0
- package/lib/helpers/toFormData.js +63 -46
- package/lib/helpers/validator.js +8 -4
- package/lib/utils.js +148 -27
- package/package.json +25 -24
- package/lib/cancel/Cancel.js +0 -19
- package/lib/core/createError.js +0 -18
- package/lib/core/enhanceError.js +0 -43
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,47 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### 0.27.2 (April 27, 2022)
|
4
|
+
|
5
|
+
Fixes and Functionality:
|
6
|
+
- Fixed FormData posting in browser environment by reverting #3785 ([#4640](https://github.com/axios/axios/pull/4640))
|
7
|
+
- Enhanced protocol parsing implementation ([#4639](https://github.com/axios/axios/pull/4639))
|
8
|
+
- Fixed bundle size
|
9
|
+
|
10
|
+
### 0.27.1 (April 26, 2022)
|
11
|
+
|
12
|
+
Fixes and Functionality:
|
13
|
+
- Removed import of url module in browser build due to huge size overhead and builds being broken ([#4594](https://github.com/axios/axios/pull/4594))
|
14
|
+
- Bumped follow-redirects to ^1.14.9 ([#4615](https://github.com/axios/axios/pull/4615))
|
15
|
+
|
16
|
+
### 0.27.0 (April 25, 2022)
|
17
|
+
|
18
|
+
Breaking changes:
|
19
|
+
- New toFormData helper function that allows the implementor to pass an object and allow axios to convert it to FormData ([#3757](https://github.com/axios/axios/pull/3757))
|
20
|
+
- Removed functionality that removed the the `Content-Type` request header when passing FormData ([#3785](https://github.com/axios/axios/pull/3785))
|
21
|
+
- **(*)** Refactored error handling implementing AxiosError as a constructor, this is a large change to error handling on the whole ([#3645](https://github.com/axios/axios/pull/3645))
|
22
|
+
- Separated responsibility for FormData instantiation between `transformRequest` and `toFormData` ([#4470](https://github.com/axios/axios/pull/4470))
|
23
|
+
- **(*)** Improved and fixed multiple issues with FormData support ([#4448](https://github.com/axios/axios/pull/4448))
|
24
|
+
|
25
|
+
QOL and DevX improvements:
|
26
|
+
- Added a multipart/form-data testing playground allowing contributors to debug changes easily ([#4465](https://github.com/axios/axios/pull/4465))
|
27
|
+
|
28
|
+
Fixes and Functionality:
|
29
|
+
- Refactored project file structure to avoid circular imports ([#4515](https://github.com/axios/axios/pull/4516)) & ([#4516](https://github.com/axios/axios/pull/4516))
|
30
|
+
- Bumped follow-redirects to ^1.14.9 ([#4562](https://github.com/axios/axios/pull/4562))
|
31
|
+
|
32
|
+
Internal and Tests:
|
33
|
+
- Updated dev dependencies to latest version
|
34
|
+
|
35
|
+
Documentation:
|
36
|
+
- Fixing incorrect link in changelog ([#4551](https://github.com/axios/axios/pull/4551))
|
37
|
+
|
38
|
+
Notes:
|
39
|
+
- **(*)** Please read these pull requests before updating, these changes are very impactful and far reaching.
|
40
|
+
|
3
41
|
### 0.26.1 (March 9, 2022)
|
4
42
|
|
5
43
|
Fixes and Functionality:
|
6
|
-
- Refactored project file structure to avoid circular imports ([
|
44
|
+
- Refactored project file structure to avoid circular imports ([#4220](https://github.com/axios/axios/pull/4220))
|
7
45
|
|
8
46
|
### 0.26.0 (February 13, 2022)
|
9
47
|
|
@@ -11,7 +49,7 @@ Fixes and Functionality:
|
|
11
49
|
- Fixed The timeoutErrorMessage property in config not work with Node.js ([#3581](https://github.com/axios/axios/pull/3581))
|
12
50
|
- Added errors to be displayed when the query parsing process itself fails ([#3961](https://github.com/axios/axios/pull/3961))
|
13
51
|
- Fix/remove url required ([#4426](https://github.com/axios/axios/pull/4426))
|
14
|
-
- Update follow-redirects dependency due to
|
52
|
+
- Update follow-redirects dependency due to Vulnerability ([#4462](https://github.com/axios/axios/pull/4462))
|
15
53
|
- Bump karma from 6.3.11 to 6.3.14 ([#4461](https://github.com/axios/axios/pull/4461))
|
16
54
|
- Bump follow-redirects from 1.14.7 to 1.14.8 ([#4473](https://github.com/axios/axios/pull/4473))
|
17
55
|
|
@@ -19,7 +57,7 @@ Fixes and Functionality:
|
|
19
57
|
|
20
58
|
Breaking changes:
|
21
59
|
- Fixing maxBodyLength enforcement ([#3786](https://github.com/axios/axios/pull/3786))
|
22
|
-
- Don't rely on strict mode
|
60
|
+
- Don't rely on strict mode behavior for arguments ([#3470](https://github.com/axios/axios/pull/3470))
|
23
61
|
- Adding error handling when missing url ([#3791](https://github.com/axios/axios/pull/3791))
|
24
62
|
- Update isAbsoluteURL.js removing escaping of non-special characters ([#3809](https://github.com/axios/axios/pull/3809))
|
25
63
|
- Use native Array.isArray() in utils.js ([#3836](https://github.com/axios/axios/pull/3836))
|
@@ -36,14 +74,13 @@ Fixes and Functionality:
|
|
36
74
|
- Adding responseEncoding prop type in AxiosRequestConfig ([#3918](https://github.com/axios/axios/pull/3918))
|
37
75
|
|
38
76
|
Internal and Tests:
|
39
|
-
- Adding axios-test-instance to ecosystem ([#
|
77
|
+
- Adding axios-test-instance to ecosystem ([#3496](https://github.com/axios/axios/pull/3496))
|
40
78
|
- Optimize the logic of isAxiosError ([#3546](https://github.com/axios/axios/pull/3546))
|
41
79
|
- Add tests and documentation to display how multiple inceptors work ([#3564](https://github.com/axios/axios/pull/3564))
|
42
80
|
- Updating follow-redirects to version 1.14.7 ([#4379](https://github.com/axios/axios/pull/4379))
|
43
81
|
|
44
|
-
|
45
82
|
Documentation:
|
46
|
-
- Fixing changelog to show
|
83
|
+
- Fixing changelog to show correct pull request ([#4219](https://github.com/axios/axios/pull/4219))
|
47
84
|
- Update upgrade guide for https proxy setting ([#3604](https://github.com/axios/axios/pull/3604))
|
48
85
|
|
49
86
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
@@ -134,7 +171,7 @@ Huge thanks to everyone who contributed to this release via code (authors listed
|
|
134
171
|
### 0.21.4 (September 6, 2021)
|
135
172
|
|
136
173
|
Fixes and Functionality:
|
137
|
-
- Fixing JSON transform when data is stringified. Providing backward
|
174
|
+
- 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))
|
138
175
|
|
139
176
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
140
177
|
|
@@ -169,9 +206,9 @@ Fixes and Functionality:
|
|
169
206
|
|
170
207
|
Internal and Tests:
|
171
208
|
|
172
|
-
- Updating build dev
|
209
|
+
- Updating build dev dependencies ([#3401](https://github.com/axios/axios/pull/3401))
|
173
210
|
- Fixing builds running on Travis CI ([#3538](https://github.com/axios/axios/pull/3538))
|
174
|
-
- Updating follow
|
211
|
+
- Updating follow redirect version ([#3694](https://github.com/axios/axios/pull/3694), [#3771](https://github.com/axios/axios/pull/3771))
|
175
212
|
- 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))
|
176
213
|
- Updating content-type header for application/json to not contain charset field, according do RFC 8259 ([#2154](https://github.com/axios/axios/pull/2154))
|
177
214
|
- Fixing tests by bumping karma-sauce-launcher version ([#3813](https://github.com/axios/axios/pull/3813))
|
@@ -181,9 +218,9 @@ Documentation:
|
|
181
218
|
|
182
219
|
- Updating documentation around the use of `AUTH_TOKEN` with multiple domain endpoints ([#3539](https://github.com/axios/axios/pull/3539))
|
183
220
|
- Remove duplication of item in changelog ([#3523](https://github.com/axios/axios/pull/3523))
|
184
|
-
- Fixing
|
221
|
+
- Fixing grammatical errors ([#2642](https://github.com/axios/axios/pull/2642))
|
185
222
|
- Fixing spelling error ([#3567](https://github.com/axios/axios/pull/3567))
|
186
|
-
- Moving gitpod
|
223
|
+
- Moving gitpod mention ([#2637](https://github.com/axios/axios/pull/2637))
|
187
224
|
- Adding new axios documentation website link ([#3681](https://github.com/axios/axios/pull/3681), [#3707](https://github.com/axios/axios/pull/3707))
|
188
225
|
- Updating documentation around dispatching requests ([#3772](https://github.com/axios/axios/pull/3772))
|
189
226
|
- Adding documentation for the type guard isAxiosError ([#3767](https://github.com/axios/axios/pull/3767))
|
@@ -261,7 +298,7 @@ Internal and Tests:
|
|
261
298
|
|
262
299
|
Documentation:
|
263
300
|
|
264
|
-
- Fixing simple typo,
|
301
|
+
- Fixing simple typo, existent -> existent ([#3252](https://github.com/axios/axios/pull/3252))
|
265
302
|
- Fixing typos ([#3309](https://github.com/axios/axios/pull/3309))
|
266
303
|
|
267
304
|
Huge thanks to everyone who contributed to this release via code (authors listed below) or via reviews and triaging on GitHub:
|
package/README.md
CHANGED
@@ -23,7 +23,7 @@ Promise based HTTP client for the browser and node.js
|
|
23
23
|
- [Example](#example)
|
24
24
|
- [Axios API](#axios-api)
|
25
25
|
- [Request method aliases](#request-method-aliases)
|
26
|
-
- [Concurrency
|
26
|
+
- [Concurrency 👎](#concurrency-deprecated)
|
27
27
|
- [Creating an instance](#creating-an-instance)
|
28
28
|
- [Instance methods](#instance-methods)
|
29
29
|
- [Request Config](#request-config)
|
@@ -36,11 +36,15 @@ Promise based HTTP client for the browser and node.js
|
|
36
36
|
- [Multiple Interceptors](#multiple-interceptors)
|
37
37
|
- [Handling Errors](#handling-errors)
|
38
38
|
- [Cancellation](#cancellation)
|
39
|
+
- [AbortController](#abortcontroller)
|
40
|
+
- [CancelToken 👎](#canceltoken-deprecated)
|
39
41
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
40
42
|
- [Browser](#browser)
|
41
43
|
- [Node.js](#nodejs)
|
42
44
|
- [Query string](#query-string)
|
43
45
|
- [Form data](#form-data)
|
46
|
+
- [Automatic serialization](#-automatic-serialization)
|
47
|
+
- [Manual FormData passing](#manual-formdata-passing)
|
44
48
|
- [Semver](#semver)
|
45
49
|
- [Promises](#promises)
|
46
50
|
- [TypeScript](#typescript)
|
@@ -113,7 +117,7 @@ const axios = require('axios').default;
|
|
113
117
|
Performing a `GET` request
|
114
118
|
|
115
119
|
```js
|
116
|
-
const axios = require('axios');
|
120
|
+
const axios = require('axios').default;
|
117
121
|
|
118
122
|
// Make a request for a user with a given ID
|
119
123
|
axios.get('/user?ID=12345')
|
@@ -231,7 +235,7 @@ axios('/user/12345');
|
|
231
235
|
|
232
236
|
### Request method aliases
|
233
237
|
|
234
|
-
For convenience aliases have been provided for all
|
238
|
+
For convenience, aliases have been provided for all common request methods.
|
235
239
|
|
236
240
|
##### axios.request(config)
|
237
241
|
##### axios.get(url[, config])
|
@@ -414,7 +418,18 @@ These are the available config options for making requests. Only the `url` is re
|
|
414
418
|
|
415
419
|
// `maxRedirects` defines the maximum number of redirects to follow in node.js.
|
416
420
|
// If set to 0, no redirects will be followed.
|
417
|
-
maxRedirects:
|
421
|
+
maxRedirects: 21, // default
|
422
|
+
|
423
|
+
// `beforeRedirect` defines a function that will be called before redirect.
|
424
|
+
// Use this to adjust the request options upon redirecting,
|
425
|
+
// to inspect the latest response headers,
|
426
|
+
// or to cancel the request by throwing an error
|
427
|
+
// If maxRedirects is set to 0, `beforeRedirect` is not used.
|
428
|
+
beforeRedirect: (options, { headers }) => {
|
429
|
+
if (options.hostname === "example.com") {
|
430
|
+
options.auth = "user:password";
|
431
|
+
}
|
432
|
+
};
|
418
433
|
|
419
434
|
// `socketPath` defines a UNIX Socket to be used in node.js.
|
420
435
|
// e.g. '/var/run/docker.sock' to send requests to the docker daemon.
|
@@ -483,6 +498,11 @@ These are the available config options for making requests. Only the `url` is re
|
|
483
498
|
|
484
499
|
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
485
500
|
clarifyTimeoutError: false,
|
501
|
+
},
|
502
|
+
|
503
|
+
env: {
|
504
|
+
// The FormData class to be used to automatically serialize the payload into a FormData object
|
505
|
+
FormData: window?.FormData || global?.FormData
|
486
506
|
}
|
487
507
|
}
|
488
508
|
```
|
@@ -707,10 +727,30 @@ axios.get('/user/12345')
|
|
707
727
|
|
708
728
|
## Cancellation
|
709
729
|
|
710
|
-
|
730
|
+
### AbortController
|
731
|
+
|
732
|
+
Starting from `v0.22.0` Axios supports AbortController to cancel requests in fetch API way:
|
733
|
+
|
734
|
+
```js
|
735
|
+
const controller = new AbortController();
|
736
|
+
|
737
|
+
axios.get('/foo/bar', {
|
738
|
+
signal: controller.signal
|
739
|
+
}).then(function(response) {
|
740
|
+
//...
|
741
|
+
});
|
742
|
+
// cancel the request
|
743
|
+
controller.abort()
|
744
|
+
```
|
745
|
+
|
746
|
+
### CancelToken `👎deprecated`
|
747
|
+
|
748
|
+
You can also cancel a request using a *CancelToken*.
|
711
749
|
|
712
750
|
> The axios cancel token API is based on the withdrawn [cancelable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
|
713
751
|
|
752
|
+
> This API is deprecated since v0.22.0 and shouldn't be used in new projects
|
753
|
+
|
714
754
|
You can create a cancel token using the `CancelToken.source` factory as shown below:
|
715
755
|
|
716
756
|
```js
|
@@ -754,22 +794,11 @@ axios.get('/user/12345', {
|
|
754
794
|
cancel();
|
755
795
|
```
|
756
796
|
|
757
|
-
Axios supports AbortController to abort requests in [`fetch API`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API#aborting_a_fetch) way:
|
758
|
-
```js
|
759
|
-
const controller = new AbortController();
|
760
|
-
|
761
|
-
axios.get('/foo/bar', {
|
762
|
-
signal: controller.signal
|
763
|
-
}).then(function(response) {
|
764
|
-
//...
|
765
|
-
});
|
766
|
-
// cancel the request
|
767
|
-
controller.abort()
|
768
|
-
```
|
769
|
-
|
770
797
|
> Note: you can cancel several requests with the same cancel token/abort controller.
|
771
798
|
> 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.
|
772
799
|
|
800
|
+
> During the transition period, you can use both cancellation APIs, even for the same request:
|
801
|
+
|
773
802
|
## Using application/x-www-form-urlencoded format
|
774
803
|
|
775
804
|
By default, axios serializes JavaScript objects to `JSON`. To send data in the `application/x-www-form-urlencoded` format instead, you can use one of the following options.
|
@@ -829,11 +858,75 @@ axios.post('http://something.com/', params.toString());
|
|
829
858
|
|
830
859
|
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
831
860
|
|
832
|
-
|
833
|
-
The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues
|
861
|
+
> NOTE:
|
862
|
+
> The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has [known issues](https://github.com/nodejs/node-v0.x-archive/issues/1665) with that use case.
|
834
863
|
|
835
864
|
#### Form data
|
836
865
|
|
866
|
+
##### 🆕 Automatic serialization
|
867
|
+
|
868
|
+
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
869
|
+
header is set to `multipart/form-data`.
|
870
|
+
|
871
|
+
The following request will submit the data in a FormData format (Browser & Node.js):
|
872
|
+
|
873
|
+
```js
|
874
|
+
import axios from 'axios';
|
875
|
+
|
876
|
+
axios.post('https://httpbin.org/post', {x: 1}, {
|
877
|
+
headers: {
|
878
|
+
'Content-Type': 'multipart/form-data'
|
879
|
+
}
|
880
|
+
}).then(({data})=> console.log(data));
|
881
|
+
```
|
882
|
+
|
883
|
+
In the `node.js` build, the ([`form-data`](https://github.com/form-data/form-data)) polyfill is used by default.
|
884
|
+
|
885
|
+
You can overload the FormData class by setting the `env.FormData` config variable,
|
886
|
+
but you probably won't need it in most cases:
|
887
|
+
|
888
|
+
```js
|
889
|
+
const axios= require('axios');
|
890
|
+
var FormData = require('form-data');
|
891
|
+
|
892
|
+
axios.post('https://httpbin.org/post', {x: 1, buf: new Buffer(10)}, {
|
893
|
+
headers: {
|
894
|
+
'Content-Type': 'multipart/form-data'
|
895
|
+
}
|
896
|
+
}).then(({data})=> console.log(data));
|
897
|
+
```
|
898
|
+
|
899
|
+
Axios FormData serializer supports some special endings to perform the following operations:
|
900
|
+
|
901
|
+
- `{}` - serialize the value with JSON.stringify
|
902
|
+
- `[]` - unwrap the array like object as separate fields with the same key
|
903
|
+
|
904
|
+
```js
|
905
|
+
const axios= require('axios');
|
906
|
+
|
907
|
+
axios.post('https://httpbin.org/post', {
|
908
|
+
'myObj{}': {x: 1, s: "foo"},
|
909
|
+
'files[]': document.querySelector('#fileInput').files
|
910
|
+
}, {
|
911
|
+
headers: {
|
912
|
+
'Content-Type': 'multipart/form-data'
|
913
|
+
}
|
914
|
+
}).then(({data})=> console.log(data));
|
915
|
+
```
|
916
|
+
|
917
|
+
Axios supports the following shortcut methods: `postForm`, `putForm`, `patchForm`
|
918
|
+
which are just the corresponding http methods with a header preset: `Content-Type`: `multipart/form-data`.
|
919
|
+
|
920
|
+
FileList object can be passed directly:
|
921
|
+
|
922
|
+
```js
|
923
|
+
await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files)
|
924
|
+
```
|
925
|
+
|
926
|
+
All files will be sent with the same field names: `files[]`;
|
927
|
+
|
928
|
+
##### Manual FormData passing
|
929
|
+
|
837
930
|
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
838
931
|
|
839
932
|
```js
|
@@ -844,18 +937,7 @@ form.append('my_field', 'my value');
|
|
844
937
|
form.append('my_buffer', new Buffer(10));
|
845
938
|
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
846
939
|
|
847
|
-
axios.post('https://example.com', form
|
848
|
-
```
|
849
|
-
|
850
|
-
Alternatively, use an interceptor:
|
851
|
-
|
852
|
-
```js
|
853
|
-
axios.interceptors.request.use(config => {
|
854
|
-
if (config.data instanceof FormData) {
|
855
|
-
Object.assign(config.headers, config.data.getHeaders());
|
856
|
-
}
|
857
|
-
return config;
|
858
|
-
});
|
940
|
+
axios.post('https://example.com', form)
|
859
941
|
```
|
860
942
|
|
861
943
|
## Semver
|