axios 1.0.0-alpha.1 → 1.1.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.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +74 -1
- package/README.md +59 -48
- package/SECURITY.md +3 -2
- package/bin/ssl_hotfix.js +1 -1
- package/dist/axios.js +1564 -981
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +1472 -866
- 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 +3761 -0
- package/dist/node/axios.cjs.map +1 -0
- package/gulpfile.js +88 -0
- package/index.d.ts +213 -67
- package/index.js +2 -1
- package/karma.conf.cjs +250 -0
- package/lib/adapters/http.js +256 -131
- package/lib/adapters/index.js +33 -0
- package/lib/adapters/xhr.js +79 -56
- package/lib/axios.js +41 -25
- package/lib/cancel/CancelToken.js +91 -88
- package/lib/cancel/CanceledError.js +5 -4
- package/lib/cancel/isCancel.js +2 -2
- package/lib/core/Axios.js +127 -100
- package/lib/core/AxiosError.js +10 -7
- package/lib/core/AxiosHeaders.js +274 -0
- package/lib/core/InterceptorManager.js +61 -53
- package/lib/core/buildFullPath.js +5 -4
- package/lib/core/dispatchRequest.js +21 -39
- package/lib/core/mergeConfig.js +8 -7
- package/lib/core/settle.js +6 -4
- package/lib/core/transformData.js +15 -10
- package/lib/defaults/index.js +46 -39
- package/lib/defaults/transitional.js +1 -1
- package/lib/env/classes/FormData.js +2 -2
- package/lib/env/data.js +1 -3
- package/lib/helpers/AxiosTransformStream.js +191 -0
- package/lib/helpers/AxiosURLSearchParams.js +23 -7
- package/lib/helpers/bind.js +2 -2
- package/lib/helpers/buildURL.js +16 -7
- package/lib/helpers/combineURLs.js +3 -2
- package/lib/helpers/cookies.js +43 -44
- package/lib/helpers/deprecatedMethod.js +4 -2
- package/lib/helpers/formDataToJSON.js +36 -15
- package/lib/helpers/fromDataURI.js +15 -13
- package/lib/helpers/isAbsoluteURL.js +3 -2
- package/lib/helpers/isAxiosError.js +4 -3
- package/lib/helpers/isURLSameOrigin.js +55 -56
- package/lib/helpers/null.js +1 -1
- package/lib/helpers/parseHeaders.js +24 -22
- package/lib/helpers/parseProtocol.js +3 -3
- package/lib/helpers/speedometer.js +55 -0
- package/lib/helpers/spread.js +3 -2
- package/lib/helpers/throttle.js +33 -0
- package/lib/helpers/toFormData.js +68 -18
- package/lib/helpers/toURLEncodedForm.js +5 -5
- package/lib/helpers/validator.js +20 -15
- package/lib/platform/browser/classes/FormData.js +1 -1
- package/lib/platform/browser/classes/URLSearchParams.js +2 -3
- package/lib/platform/browser/index.js +38 -6
- package/lib/platform/index.js +2 -2
- package/lib/platform/node/classes/FormData.js +2 -2
- package/lib/platform/node/classes/URLSearchParams.js +2 -3
- package/lib/platform/node/index.js +5 -4
- package/lib/utils.js +294 -192
- package/package.json +55 -22
- package/rollup.config.js +37 -7
- package/lib/helpers/normalizeHeaderName.js +0 -12
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [1.0.0] - 2022-
|
3
|
+
## [1.0.0] - 2022-10-04
|
4
4
|
|
5
5
|
### Added
|
6
6
|
|
@@ -28,6 +28,10 @@
|
|
28
28
|
- Adding types for progress event callbacks [#4675](https://github.com/axios/axios/pull/4675)
|
29
29
|
- URL params serializer [#4734](https://github.com/axios/axios/pull/4734)
|
30
30
|
- Added axios.formToJSON method [#4735](https://github.com/axios/axios/pull/4735)
|
31
|
+
- Bower platform add data protocol [#4804](https://github.com/axios/axios/pull/4804)
|
32
|
+
- Use WHATWG URL API instead of url.parse() [#4852](https://github.com/axios/axios/pull/4852)
|
33
|
+
- Add ENUM containing Http Status Codes to typings [#4903](https://github.com/axios/axios/pull/4903)
|
34
|
+
- Improve typing of timeout in index.d.ts [#4934](https://github.com/axios/axios/pull/4934)
|
31
35
|
|
32
36
|
### Changed
|
33
37
|
|
@@ -43,8 +47,11 @@
|
|
43
47
|
- Updated type definition for axios instance methods [#4224](https://github.com/axios/axios/pull/4224)
|
44
48
|
- Updated eslint config [#4722](https://github.com/axios/axios/pull/4722)
|
45
49
|
- Updated Docs [#4742](https://github.com/axios/axios/pull/4742)
|
50
|
+
- Refactored Axios to use ES2017 [#4787](https://github.com/axios/axios/pull/4787)
|
51
|
+
|
46
52
|
|
47
53
|
### Deprecated
|
54
|
+
- There are multiple deprecations, refactors and fixes provided in this release. Please read through the full release notes to see how this may impact your project and use case.
|
48
55
|
|
49
56
|
### Removed
|
50
57
|
|
@@ -77,6 +84,30 @@
|
|
77
84
|
- Bump grunt from 1.5.2 to 1.5.3 [#4743](https://github.com/axios/axios/pull/4743)
|
78
85
|
- Fixing content-type header repeated [#4745](https://github.com/axios/axios/pull/4745)
|
79
86
|
- Fixed timeout error message for http [4738](https://github.com/axios/axios/pull/4738)
|
87
|
+
- Request ignores false, 0 and empty string as body values [#4785](https://github.com/axios/axios/pull/4785)
|
88
|
+
- Added back missing minified builds [#4805](https://github.com/axios/axios/pull/4805)
|
89
|
+
- Fixed a type error [#4815](https://github.com/axios/axios/pull/4815)
|
90
|
+
- Fixed a regression bug with unsubscribing from cancel token; [#4819](https://github.com/axios/axios/pull/4819)
|
91
|
+
- Remove repeated compression algorithm [#4820](https://github.com/axios/axios/pull/4820)
|
92
|
+
- The error of calling extend to pass parameters [#4857](https://github.com/axios/axios/pull/4857)
|
93
|
+
- SerializerOptions.indexes allows boolean | null | undefined [#4862](https://github.com/axios/axios/pull/4862)
|
94
|
+
- Require interceptors to return values [#4874](https://github.com/axios/axios/pull/4874)
|
95
|
+
- Removed unused imports [#4949](https://github.com/axios/axios/pull/4949)
|
96
|
+
- Allow null indexes on formSerializer and paramsSerializer [#4960](https://github.com/axios/axios/pull/4960)
|
97
|
+
|
98
|
+
### Chores
|
99
|
+
- Set permissions for GitHub actions [#4765](https://github.com/axios/axios/pull/4765)
|
100
|
+
- Included githubactions in the dependabot config [#4770](https://github.com/axios/axios/pull/4770)
|
101
|
+
- Included dependency review [#4771](https://github.com/axios/axios/pull/4771)
|
102
|
+
- Update security.md [#4784](https://github.com/axios/axios/pull/4784)
|
103
|
+
- Remove unnecessary spaces [#4854](https://github.com/axios/axios/pull/4854)
|
104
|
+
- Simplify the import path of AxiosError [#4875](https://github.com/axios/axios/pull/4875)
|
105
|
+
- Fix Gitpod dead link [#4941](https://github.com/axios/axios/pull/4941)
|
106
|
+
- Enable syntax highlighting for a code block [#4970](https://github.com/axios/axios/pull/4970)
|
107
|
+
- Using Logo Axios in Readme.md [#4993](https://github.com/axios/axios/pull/4993)
|
108
|
+
- Fix markup for note in README [#4825](https://github.com/axios/axios/pull/4825)
|
109
|
+
- Fix typo and formatting, add colons [#4853](https://github.com/axios/axios/pull/4853)
|
110
|
+
- Fix typo in readme [#4942](https://github.com/axios/axios/pull/4942)
|
80
111
|
|
81
112
|
### Security
|
82
113
|
|
@@ -125,3 +156,45 @@
|
|
125
156
|
- [chenjigeng](https://github.com/chenjigeng)
|
126
157
|
- [João Gabriel Quaresma](https://github.com/joaoGabriel55)
|
127
158
|
- [Victor Augusto](https://github.com/VictorAugDB)
|
159
|
+
- [neilnaveen](https://github.com/neilnaveen)
|
160
|
+
- [Pavlos](https://github.com/psmoros)
|
161
|
+
- [Kiryl Valkovich](https://github.com/visortelle)
|
162
|
+
- [Naveen](https://github.com/naveensrinivasan)
|
163
|
+
- [wenzheng](https://github.com/0x30)
|
164
|
+
- [hcwhan](https://github.com/hcwhan)
|
165
|
+
- [Bassel Rachid](https://github.com/basselworkforce)
|
166
|
+
- [Grégoire Pineau](https://github.com/lyrixx)
|
167
|
+
- [felipedamin](https://github.com/felipedamin)
|
168
|
+
- [Karl Horky](https://github.com/karlhorky)
|
169
|
+
- [Yue JIN](https://github.com/kingyue737)
|
170
|
+
- [Usman Ali Siddiqui](https://github.com/usman250994)
|
171
|
+
- [WD](https://github.com/techbirds)
|
172
|
+
- [Günther Foidl](https://github.com/gfoidl)
|
173
|
+
- [Stephen Jennings](https://github.com/jennings)
|
174
|
+
- [C.T.Lin](https://github.com/chentsulin)
|
175
|
+
- [mia-z](https://github.com/mia-z)
|
176
|
+
- [Parth Banathia](https://github.com/Parth0105)
|
177
|
+
- [parth0105pluang](https://github.com/parth0105pluang)
|
178
|
+
- [Marco Weber](https://github.com/mrcwbr)
|
179
|
+
- [Luca Pizzini](https://github.com/lpizzinidev)
|
180
|
+
- [Willian Agostini](https://github.com/WillianAgostini)
|
181
|
+
- [Huyen Nguyen](https://github.com/huyenltnguyen)
|
182
|
+
|
183
|
+
## [1.1.0] - 2022-10-06
|
184
|
+
|
185
|
+
### Fixed
|
186
|
+
|
187
|
+
- Fixed missing exports in type definition index.d.ts [#5003](https://github.com/axios/axios/pull/5003)
|
188
|
+
- Fixed query params composing [#5018](https://github.com/axios/axios/pull/5018)
|
189
|
+
- Fixed GenericAbortSignal interface by making it more generic [#5021](https://github.com/axios/axios/pull/5021)
|
190
|
+
- Fixed adding "clear" to AxiosInterceptorManager [#5010](https://github.com/axios/axios/pull/5010)
|
191
|
+
- Fixed commonjs & umd exports [#5030](https://github.com/axios/axios/pull/5030)
|
192
|
+
- Fixed inability to access response headers when using axios 1.x with Jest [#5036](https://github.com/axios/axios/pull/5036)
|
193
|
+
|
194
|
+
### Contributors to this release
|
195
|
+
|
196
|
+
- [Trim21](https://github.com/trim21)
|
197
|
+
- [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS)
|
198
|
+
- [shingo.sasaki](https://github.com/s-sasaki-0529)
|
199
|
+
- [Ivan Pepelko](https://github.com/ivanpepelko)
|
200
|
+
- [Richard Kořínek](https://github.com/risa)
|
package/README.md
CHANGED
@@ -1,9 +1,22 @@
|
|
1
|
-
|
1
|
+
<h1 align="center">
|
2
|
+
<b>
|
3
|
+
<a href="https://axios-http.com"><img src="https://axios-http.com/assets/logo.svg" /></a><br>
|
4
|
+
</b>
|
5
|
+
</h1>
|
6
|
+
|
7
|
+
<p align="center">Promise based HTTP client for the browser and node.js</p>
|
8
|
+
|
9
|
+
<p align="center">
|
10
|
+
<a href="https://axios-http.com/"><b>Website</b></a> •
|
11
|
+
<a href="https://axios-http.com/docs/intro"><b>Documentation</b></a>
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<div align="center">
|
2
15
|
|
3
16
|
[](https://www.npmjs.org/package/axios)
|
4
17
|
[](https://cdnjs.com/libraries/axios)
|
5
18
|

|
6
|
-
[](https://gitpod.io/#https://github.com/axios/axios)
|
19
|
+
[](https://gitpod.io/#https://github.com/axios/axios)
|
7
20
|
[](https://coveralls.io/r/mzabriskie/axios)
|
8
21
|
[](https://packagephobia.now.sh/result?p=axios)
|
9
22
|
[](https://npm-stat.com/charts.html?package=axios)
|
@@ -12,10 +25,8 @@
|
|
12
25
|
[](https://snyk.io/test/npm/axios)
|
13
26
|

|
14
27
|
|
15
|
-
|
16
|
-
|
17
|
-
> New axios docs website: [click here](https://axios-http.com/)
|
18
|
-
|
28
|
+
</div>
|
29
|
+
|
19
30
|
## Table of Contents
|
20
31
|
|
21
32
|
- [Features](#features)
|
@@ -42,12 +53,12 @@ Promise based HTTP client for the browser and node.js
|
|
42
53
|
- [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
|
43
54
|
- [URLSearchParams](#urlsearchparams)
|
44
55
|
- [Query string](#query-string-older-browsers)
|
45
|
-
- [🆕 Automatic serialization](#-automatic-serialization-to-urlsearchparams)
|
46
|
-
- [Using multipart/form-data format](#using-multipartform-data-format)
|
56
|
+
- [🆕 Automatic serialization](#-automatic-serialization-to-urlsearchparams)
|
57
|
+
- [Using multipart/form-data format](#using-multipartform-data-format)
|
47
58
|
- [FormData](#formdata)
|
48
|
-
- [🆕 Automatic serialization](#-automatic-serialization-to-formdata)
|
59
|
+
- [🆕 Automatic serialization](#-automatic-serialization-to-formdata)
|
49
60
|
- [Files Posting](#files-posting)
|
50
|
-
- [HTML Form Posting](
|
61
|
+
- [HTML Form Posting](#-html-form-posting-browser)
|
51
62
|
- [Semver](#semver)
|
52
63
|
- [Promises](#promises)
|
53
64
|
- [TypeScript](#typescript)
|
@@ -139,7 +150,7 @@ axios.get('/user?ID=12345')
|
|
139
150
|
// handle error
|
140
151
|
console.log(error);
|
141
152
|
})
|
142
|
-
.
|
153
|
+
.finally(function () {
|
143
154
|
// always executed
|
144
155
|
});
|
145
156
|
|
@@ -155,9 +166,9 @@ axios.get('/user', {
|
|
155
166
|
.catch(function (error) {
|
156
167
|
console.log(error);
|
157
168
|
})
|
158
|
-
.
|
169
|
+
.finally(function () {
|
159
170
|
// always executed
|
160
|
-
});
|
171
|
+
});
|
161
172
|
|
162
173
|
// Want to use async/await? Add the `async` keyword to your outer function/method.
|
163
174
|
async function getUser() {
|
@@ -170,7 +181,7 @@ async function getUser() {
|
|
170
181
|
}
|
171
182
|
```
|
172
183
|
|
173
|
-
> **
|
184
|
+
> **Note** `async/await` is part of ECMAScript 2017 and is not supported in Internet
|
174
185
|
> Explorer and older browsers, so use with caution.
|
175
186
|
|
176
187
|
Performing a `POST` request
|
@@ -354,7 +365,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
354
365
|
data: {
|
355
366
|
firstName: 'Fred'
|
356
367
|
},
|
357
|
-
|
368
|
+
|
358
369
|
// syntax alternative to send data into the body
|
359
370
|
// method post
|
360
371
|
// only the value is sent, not the key
|
@@ -462,7 +473,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
462
473
|
// supplies credentials.
|
463
474
|
// This will set an `Proxy-Authorization` header, overwriting any existing
|
464
475
|
// `Proxy-Authorization` custom headers you have set using `headers`.
|
465
|
-
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
476
|
+
// If the proxy server uses HTTPS, then you must set the protocol to `https`.
|
466
477
|
proxy: {
|
467
478
|
protocol: 'https',
|
468
479
|
host: '127.0.0.1',
|
@@ -481,8 +492,8 @@ These are the available config options for making requests. Only the `url` is re
|
|
481
492
|
// an alternative way to cancel Axios requests using AbortController
|
482
493
|
signal: new AbortController().signal,
|
483
494
|
|
484
|
-
// `decompress` indicates whether or not the response body should be decompressed
|
485
|
-
// automatically. If set to `true` will also remove the 'content-encoding' header
|
495
|
+
// `decompress` indicates whether or not the response body should be decompressed
|
496
|
+
// automatically. If set to `true` will also remove the 'content-encoding' header
|
486
497
|
// from the responses objects of all decompressed responses
|
487
498
|
// - Node only (XHR cannot turn off decompression)
|
488
499
|
decompress: true // default
|
@@ -504,7 +515,7 @@ These are the available config options for making requests. Only the `url` is re
|
|
504
515
|
|
505
516
|
// try to parse the response string as JSON even if `responseType` is not 'json'
|
506
517
|
forcedJSONParsing: true,
|
507
|
-
|
518
|
+
|
508
519
|
// throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
|
509
520
|
clarifyTimeoutError: false,
|
510
521
|
},
|
@@ -515,9 +526,9 @@ These are the available config options for making requests. Only the `url` is re
|
|
515
526
|
},
|
516
527
|
|
517
528
|
formSerializer: {
|
518
|
-
visitor: (value, key, path, helpers)=> {}; // custom visitor funaction to serrialize form values
|
529
|
+
visitor: (value, key, path, helpers) => {}; // custom visitor funaction to serrialize form values
|
519
530
|
dots: boolean; // use dots instead of brackets format
|
520
|
-
metaTokens: boolean; // keep special endings like {} in parameter key
|
531
|
+
metaTokens: boolean; // keep special endings like {} in parameter key
|
521
532
|
indexes: boolean; // array indexes format null - no brackets, false - empty brackets, true - brackets with indexes
|
522
533
|
}
|
523
534
|
}
|
@@ -665,7 +676,7 @@ instance.interceptors.request.use(function () {/*...*/});
|
|
665
676
|
```
|
666
677
|
|
667
678
|
When you add request interceptors, they are presumed to be asynchronous by default. This can cause a delay
|
668
|
-
in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
|
679
|
+
in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
|
669
680
|
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
|
670
681
|
to the options object that will tell axios to run the code synchronously and avoid any delays in request execution.
|
671
682
|
|
@@ -676,7 +687,7 @@ axios.interceptors.request.use(function (config) {
|
|
676
687
|
}, null, { synchronous: true });
|
677
688
|
```
|
678
689
|
|
679
|
-
If you want to execute a particular interceptor based on a runtime check,
|
690
|
+
If you want to execute a particular interceptor based on a runtime check,
|
680
691
|
you can add a `runWhen` function to the options object. The interceptor will not be executed **if and only if** the return
|
681
692
|
of `runWhen` is `false`. The function will be called with the config
|
682
693
|
object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
|
@@ -704,7 +715,7 @@ and when the response was fulfilled
|
|
704
715
|
- then the following fulfillment-interceptor is not called
|
705
716
|
- then the following rejection-interceptor is called
|
706
717
|
- once caught, another following fulfill-interceptor is called again (just like in a promise chain).
|
707
|
-
|
718
|
+
|
708
719
|
Read [the interceptor tests](./test/specs/interceptors.spec.js) for seeing all this in code.
|
709
720
|
|
710
721
|
## Handling Errors
|
@@ -819,7 +830,7 @@ axios.get('/user/12345', {
|
|
819
830
|
cancel();
|
820
831
|
```
|
821
832
|
|
822
|
-
> Note
|
833
|
+
> **Note:** you can cancel several requests with the same cancel token/abort controller.
|
823
834
|
> 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 a real request.
|
824
835
|
|
825
836
|
> During the transition period, you can use both cancellation APIs, even for the same request:
|
@@ -872,14 +883,14 @@ axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
|
|
872
883
|
|
873
884
|
You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
874
885
|
|
875
|
-
>
|
886
|
+
> **Note**
|
876
887
|
> 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.
|
877
888
|
|
878
889
|
### 🆕 Automatic serialization to URLSearchParams
|
879
890
|
|
880
891
|
Axios will automatically serialize the data object to urlencoded format if the content-type header is set to "application/x-www-form-urlencoded".
|
881
892
|
|
882
|
-
```
|
893
|
+
```js
|
883
894
|
const data = {
|
884
895
|
x: 1,
|
885
896
|
arr: [1, 2, 3],
|
@@ -892,7 +903,7 @@ await axios.postForm('https://postman-echo.com/post', data,
|
|
892
903
|
);
|
893
904
|
```
|
894
905
|
|
895
|
-
The server will handle it as
|
906
|
+
The server will handle it as
|
896
907
|
|
897
908
|
```js
|
898
909
|
{
|
@@ -913,9 +924,9 @@ If your backend body-parser (like `body-parser` of `express.js`) supports nested
|
|
913
924
|
|
914
925
|
```js
|
915
926
|
var app = express();
|
916
|
-
|
927
|
+
|
917
928
|
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
|
918
|
-
|
929
|
+
|
919
930
|
app.post('/', function (req, res, next) {
|
920
931
|
// echo body as JSON
|
921
932
|
res.send(JSON.stringify(req.body));
|
@@ -928,7 +939,7 @@ If your backend body-parser (like `body-parser` of `express.js`) supports nested
|
|
928
939
|
|
929
940
|
### FormData
|
930
941
|
|
931
|
-
To send the data as a `multipart/formdata` you need to pass a formData instance as a payload.
|
942
|
+
To send the data as a `multipart/formdata` you need to pass a formData instance as a payload.
|
932
943
|
Setting the `Content-Type` header is not required as Axios guesses it based on the payload type.
|
933
944
|
|
934
945
|
```js
|
@@ -937,12 +948,12 @@ formData.append('foo', 'bar');
|
|
937
948
|
|
938
949
|
axios.post('https://httpbin.org/post', formData);
|
939
950
|
```
|
940
|
-
|
951
|
+
|
941
952
|
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
942
953
|
|
943
954
|
```js
|
944
955
|
const FormData = require('form-data');
|
945
|
-
|
956
|
+
|
946
957
|
const form = new FormData();
|
947
958
|
form.append('my_field', 'my value');
|
948
959
|
form.append('my_buffer', new Buffer(10));
|
@@ -953,7 +964,7 @@ axios.post('https://example.com', form)
|
|
953
964
|
|
954
965
|
### 🆕 Automatic serialization to FormData
|
955
966
|
|
956
|
-
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
967
|
+
Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
|
957
968
|
header is set to `multipart/form-data`.
|
958
969
|
|
959
970
|
The following request will submit the data in a FormData format (Browser & Node.js):
|
@@ -965,7 +976,7 @@ axios.post('https://httpbin.org/post', {x: 1}, {
|
|
965
976
|
headers: {
|
966
977
|
'Content-Type': 'multipart/form-data'
|
967
978
|
}
|
968
|
-
}).then(({data})=> console.log(data));
|
979
|
+
}).then(({data}) => console.log(data));
|
969
980
|
```
|
970
981
|
|
971
982
|
In the `node.js` build, the ([`form-data`](https://github.com/form-data/form-data)) polyfill is used by default.
|
@@ -974,22 +985,22 @@ You can overload the FormData class by setting the `env.FormData` config variabl
|
|
974
985
|
but you probably won't need it in most cases:
|
975
986
|
|
976
987
|
```js
|
977
|
-
const axios= require('axios');
|
988
|
+
const axios = require('axios');
|
978
989
|
var FormData = require('form-data');
|
979
990
|
|
980
991
|
axios.post('https://httpbin.org/post', {x: 1, buf: new Buffer(10)}, {
|
981
992
|
headers: {
|
982
993
|
'Content-Type': 'multipart/form-data'
|
983
994
|
}
|
984
|
-
}).then(({data})=> console.log(data));
|
995
|
+
}).then(({data}) => console.log(data));
|
985
996
|
```
|
986
997
|
|
987
998
|
Axios FormData serializer supports some special endings to perform the following operations:
|
988
999
|
|
989
1000
|
- `{}` - serialize the value with JSON.stringify
|
990
|
-
- `[]` - unwrap the array-like object as separate fields with the same key
|
1001
|
+
- `[]` - unwrap the array-like object as separate fields with the same key
|
991
1002
|
|
992
|
-
>
|
1003
|
+
> **Note**
|
993
1004
|
> unwrap/expand operation will be used by default on arrays and FileList objects
|
994
1005
|
|
995
1006
|
FormData serializer supports additional options via `config.formSerializer: object` property to handle rare cases:
|
@@ -999,15 +1010,15 @@ to a `FormData` object by following custom rules.
|
|
999
1010
|
|
1000
1011
|
- `dots: boolean = false` - use dot notation instead of brackets to serialize arrays and objects;
|
1001
1012
|
|
1002
|
-
- `metaTokens: boolean = true` - add the special ending (e.g `user{}: '{"name": "John"}'`) in the FormData key.
|
1013
|
+
- `metaTokens: boolean = true` - add the special ending (e.g `user{}: '{"name": "John"}'`) in the FormData key.
|
1003
1014
|
The back-end body-parser could potentially use this meta-information to automatically parse the value as JSON.
|
1004
1015
|
|
1005
1016
|
- `indexes: null|false|true = false` - controls how indexes will be added to unwrapped keys of `flat` array-like objects
|
1006
1017
|
|
1007
|
-
- `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
|
1018
|
+
- `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
|
1008
1019
|
- `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
|
1009
1020
|
- `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
|
1010
|
-
|
1021
|
+
|
1011
1022
|
Let's say we have an object like this one:
|
1012
1023
|
|
1013
1024
|
```js
|
@@ -1023,7 +1034,7 @@ const obj = {
|
|
1023
1034
|
The following steps will be executed by the Axios serializer internally:
|
1024
1035
|
|
1025
1036
|
```js
|
1026
|
-
const formData= new FormData();
|
1037
|
+
const formData = new FormData();
|
1027
1038
|
formData.append('x', '1');
|
1028
1039
|
formData.append('arr[]', '1');
|
1029
1040
|
formData.append('arr[]', '2');
|
@@ -1043,20 +1054,20 @@ which are just the corresponding http methods with the `Content-Type` header pre
|
|
1043
1054
|
|
1044
1055
|
## Files Posting
|
1045
1056
|
|
1046
|
-
You can easily
|
1057
|
+
You can easily submit a single file:
|
1047
1058
|
|
1048
1059
|
```js
|
1049
1060
|
await axios.postForm('https://httpbin.org/post', {
|
1050
1061
|
'myVar' : 'foo',
|
1051
|
-
'file': document.querySelector('#fileInput').files[0]
|
1062
|
+
'file': document.querySelector('#fileInput').files[0]
|
1052
1063
|
});
|
1053
1064
|
```
|
1054
1065
|
|
1055
|
-
or multiple files as `multipart/form-data
|
1066
|
+
or multiple files as `multipart/form-data`:
|
1056
1067
|
|
1057
1068
|
```js
|
1058
1069
|
await axios.postForm('https://httpbin.org/post', {
|
1059
|
-
'files[]': document.querySelector('#fileInput').files
|
1070
|
+
'files[]': document.querySelector('#fileInput').files
|
1060
1071
|
});
|
1061
1072
|
```
|
1062
1073
|
|
@@ -1159,7 +1170,7 @@ try {
|
|
1159
1170
|
|
1160
1171
|
You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
|
1161
1172
|
|
1162
|
-
[](https://gitpod.io/#https://github.com/axios/axios/blob/
|
1173
|
+
[](https://gitpod.io/#https://github.com/axios/axios/blob/main/examples/server.js)
|
1163
1174
|
|
1164
1175
|
|
1165
1176
|
## Resources
|
package/SECURITY.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Reporting a Vulnerability
|
2
2
|
|
3
|
-
If you discover a security vulnerability
|
3
|
+
If you discover a security vulnerability in axios please disclose it via [our huntr page](https://huntr.dev/repos/axios/axios/). Bounty eligibility, CVE assignment, response times and past reports are all there.
|
4
4
|
|
5
|
-
|
5
|
+
|
6
|
+
Thank you for improving the security of axios.
|
package/bin/ssl_hotfix.js
CHANGED