axios 1.7.0-beta.1 → 1.7.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 +857 -827
- package/README.md +30 -1
- package/dist/axios.js +56 -41
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +22 -13
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +22 -13
- 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 +22 -13
- package/dist/node/axios.cjs.map +1 -1
- package/lib/adapters/fetch.js +20 -11
- package/lib/env/data.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -125,6 +125,7 @@
|
|
125
125
|
- [🆕 Progress capturing](#-progress-capturing)
|
126
126
|
- [🆕 Rate limiting](#-progress-capturing)
|
127
127
|
- [🆕 AxiosHeaders](#-axiosheaders)
|
128
|
+
- [🔥 Fetch adapter](#-fetch-adapter)
|
128
129
|
- [Semver](#semver)
|
129
130
|
- [Promises](#promises)
|
130
131
|
- [TypeScript](#typescript)
|
@@ -481,10 +482,13 @@ These are the available config options for making requests. Only the `url` is re
|
|
481
482
|
withCredentials: false, // default
|
482
483
|
|
483
484
|
// `adapter` allows custom handling of requests which makes testing easier.
|
484
|
-
// Return a promise and supply a valid response (see lib/adapters/README.md)
|
485
|
+
// Return a promise and supply a valid response (see lib/adapters/README.md)
|
485
486
|
adapter: function (config) {
|
486
487
|
/* ... */
|
487
488
|
},
|
489
|
+
// Also, you can set the name of the built-in adapter, or provide an array with their names
|
490
|
+
// to choose the first available in the environment
|
491
|
+
adapter: 'xhr' // 'fetch' | 'http' | ['xhr', 'http', 'fetch']
|
488
492
|
|
489
493
|
// `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
|
490
494
|
// This will set an `Authorization` header, overwriting any existing
|
@@ -1289,6 +1293,7 @@ Sending `Blobs`/`Files` as JSON (`base64`) is not currently supported.
|
|
1289
1293
|
## 🆕 Progress capturing
|
1290
1294
|
|
1291
1295
|
Axios supports both browser and node environments to capture request upload/download progress.
|
1296
|
+
The frequency of progress events is forced to be limited to `3` times per second.
|
1292
1297
|
|
1293
1298
|
```js
|
1294
1299
|
await axios.post(url, data, {
|
@@ -1609,6 +1614,30 @@ The following shortcuts are available:
|
|
1609
1614
|
|
1610
1615
|
- `setContentEncoding`, `getContentEncoding`, `hasContentEncoding`
|
1611
1616
|
|
1617
|
+
## 🔥 Fetch adapter
|
1618
|
+
|
1619
|
+
Fetch adapter was introduced in `v1.7.0`. By default, it will be used if `xhr` and `http` adapters are not available in the build,
|
1620
|
+
or not supported by the environment.
|
1621
|
+
To use it by default, it must be selected explicitly:
|
1622
|
+
|
1623
|
+
```js
|
1624
|
+
const {data} = axios.get(url, {
|
1625
|
+
adapter: 'fetch' // by default ['xhr', 'http', 'fetch']
|
1626
|
+
})
|
1627
|
+
```
|
1628
|
+
|
1629
|
+
You can create a separate instance for this:
|
1630
|
+
|
1631
|
+
```js
|
1632
|
+
const fetchAxios = axios.create({
|
1633
|
+
adapter: 'fetch'
|
1634
|
+
});
|
1635
|
+
|
1636
|
+
const {data} = fetchAxios.get(url);
|
1637
|
+
```
|
1638
|
+
|
1639
|
+
The adapter supports the same functionality as `xhr` adapter, **including upload and download progress capturing**.
|
1640
|
+
Also, it supports additional response types such as `stream` and `formdata` (if supported by the environment).
|
1612
1641
|
|
1613
1642
|
## Semver
|
1614
1643
|
|
package/dist/axios.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// Axios v1.7.0
|
1
|
+
// Axios v1.7.0 Copyright (c) 2024 Matt Zabriskie and contributors
|
2
2
|
(function (global, factory) {
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
@@ -3266,39 +3266,45 @@
|
|
3266
3266
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
3267
3267
|
while (1) switch (_context.prev = _context.next) {
|
3268
3268
|
case 0:
|
3269
|
-
if (!
|
3269
|
+
if (!(body == null)) {
|
3270
3270
|
_context.next = 2;
|
3271
3271
|
break;
|
3272
3272
|
}
|
3273
|
-
return _context.abrupt("return",
|
3273
|
+
return _context.abrupt("return", 0);
|
3274
3274
|
case 2:
|
3275
|
+
if (!utils$1.isBlob(body)) {
|
3276
|
+
_context.next = 4;
|
3277
|
+
break;
|
3278
|
+
}
|
3279
|
+
return _context.abrupt("return", body.size);
|
3280
|
+
case 4:
|
3275
3281
|
if (!utils$1.isSpecCompliantForm(body)) {
|
3276
|
-
_context.next =
|
3282
|
+
_context.next = 8;
|
3277
3283
|
break;
|
3278
3284
|
}
|
3279
|
-
_context.next =
|
3285
|
+
_context.next = 7;
|
3280
3286
|
return new Request(body).arrayBuffer();
|
3281
|
-
case
|
3287
|
+
case 7:
|
3282
3288
|
return _context.abrupt("return", _context.sent.byteLength);
|
3283
|
-
case
|
3289
|
+
case 8:
|
3284
3290
|
if (!utils$1.isArrayBufferView(body)) {
|
3285
|
-
_context.next =
|
3291
|
+
_context.next = 10;
|
3286
3292
|
break;
|
3287
3293
|
}
|
3288
3294
|
return _context.abrupt("return", body.byteLength);
|
3289
|
-
case
|
3295
|
+
case 10:
|
3290
3296
|
if (utils$1.isURLSearchParams(body)) {
|
3291
3297
|
body = body + '';
|
3292
3298
|
}
|
3293
3299
|
if (!utils$1.isString(body)) {
|
3294
|
-
_context.next =
|
3300
|
+
_context.next = 15;
|
3295
3301
|
break;
|
3296
3302
|
}
|
3297
|
-
_context.next =
|
3303
|
+
_context.next = 14;
|
3298
3304
|
return new TextEncoder().encode(body);
|
3299
|
-
case
|
3305
|
+
case 14:
|
3300
3306
|
return _context.abrupt("return", _context.sent.byteLength);
|
3301
|
-
case
|
3307
|
+
case 15:
|
3302
3308
|
case "end":
|
3303
3309
|
return _context.stop();
|
3304
3310
|
}
|
@@ -3342,56 +3348,65 @@
|
|
3342
3348
|
finished = true;
|
3343
3349
|
};
|
3344
3350
|
_context3.prev = 4;
|
3345
|
-
|
3346
|
-
|
3351
|
+
_context3.t0 = onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head';
|
3352
|
+
if (!_context3.t0) {
|
3353
|
+
_context3.next = 11;
|
3347
3354
|
break;
|
3348
3355
|
}
|
3349
|
-
_context3.next =
|
3356
|
+
_context3.next = 9;
|
3350
3357
|
return resolveBodyLength(headers, data);
|
3351
|
-
case
|
3352
|
-
requestContentLength = _context3.sent;
|
3358
|
+
case 9:
|
3359
|
+
_context3.t1 = requestContentLength = _context3.sent;
|
3360
|
+
_context3.t0 = _context3.t1 !== 0;
|
3361
|
+
case 11:
|
3362
|
+
if (!_context3.t0) {
|
3363
|
+
_context3.next = 15;
|
3364
|
+
break;
|
3365
|
+
}
|
3353
3366
|
_request = new Request(url, {
|
3354
|
-
method:
|
3367
|
+
method: 'POST',
|
3355
3368
|
body: data,
|
3356
3369
|
duplex: "half"
|
3357
3370
|
});
|
3358
3371
|
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
3359
3372
|
headers.setContentType(contentTypeHeader);
|
3360
3373
|
}
|
3361
|
-
|
3362
|
-
|
3374
|
+
if (_request.body) {
|
3375
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(requestContentLength, progressEventReducer(onUploadProgress)));
|
3376
|
+
}
|
3377
|
+
case 15:
|
3363
3378
|
if (!utils$1.isString(withCredentials)) {
|
3364
3379
|
withCredentials = withCredentials ? 'cors' : 'omit';
|
3365
3380
|
}
|
3366
3381
|
request = new Request(url, _objectSpread2(_objectSpread2({}, fetchOptions), {}, {
|
3367
3382
|
signal: composedSignal,
|
3368
|
-
method: method,
|
3383
|
+
method: method.toUpperCase(),
|
3369
3384
|
headers: headers.normalize().toJSON(),
|
3370
3385
|
body: data,
|
3371
3386
|
duplex: "half",
|
3372
3387
|
withCredentials: withCredentials
|
3373
3388
|
}));
|
3374
|
-
_context3.next =
|
3389
|
+
_context3.next = 19;
|
3375
3390
|
return fetch(request);
|
3376
|
-
case
|
3391
|
+
case 19:
|
3377
3392
|
response = _context3.sent;
|
3378
|
-
isStreamResponse = responseType === 'stream' || responseType === 'response';
|
3393
|
+
isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
3379
3394
|
if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
|
3380
3395
|
options = {};
|
3381
|
-
|
3396
|
+
['status', 'statusText', 'headers'].forEach(function (prop) {
|
3382
3397
|
options[prop] = response[prop];
|
3383
3398
|
});
|
3384
3399
|
responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
3385
3400
|
response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(responseContentLength, progressEventReducer(onDownloadProgress, true)), isStreamResponse && onFinish), options);
|
3386
3401
|
}
|
3387
3402
|
responseType = responseType || 'text';
|
3388
|
-
_context3.next =
|
3403
|
+
_context3.next = 25;
|
3389
3404
|
return resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
3390
|
-
case
|
3405
|
+
case 25:
|
3391
3406
|
responseData = _context3.sent;
|
3392
3407
|
!isStreamResponse && onFinish();
|
3393
3408
|
stopTimeout && stopTimeout();
|
3394
|
-
_context3.next =
|
3409
|
+
_context3.next = 30;
|
3395
3410
|
return new Promise(function (resolve, reject) {
|
3396
3411
|
settle(resolve, reject, {
|
3397
3412
|
data: responseData,
|
@@ -3402,26 +3417,26 @@
|
|
3402
3417
|
request: request
|
3403
3418
|
});
|
3404
3419
|
});
|
3405
|
-
case 27:
|
3406
|
-
return _context3.abrupt("return", _context3.sent);
|
3407
3420
|
case 30:
|
3408
|
-
_context3.
|
3409
|
-
|
3421
|
+
return _context3.abrupt("return", _context3.sent);
|
3422
|
+
case 33:
|
3423
|
+
_context3.prev = 33;
|
3424
|
+
_context3.t2 = _context3["catch"](4);
|
3410
3425
|
onFinish();
|
3411
|
-
if (!(_context3.
|
3412
|
-
_context3.next =
|
3426
|
+
if (!(_context3.t2 && _context3.t2.name === 'TypeError' && /fetch/i.test(_context3.t2.message))) {
|
3427
|
+
_context3.next = 38;
|
3413
3428
|
break;
|
3414
3429
|
}
|
3415
3430
|
throw Object.assign(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request), {
|
3416
|
-
cause: _context3.
|
3431
|
+
cause: _context3.t2.cause || _context3.t2
|
3417
3432
|
});
|
3418
|
-
case
|
3419
|
-
throw AxiosError.from(_context3.
|
3420
|
-
case
|
3433
|
+
case 38:
|
3434
|
+
throw AxiosError.from(_context3.t2, _context3.t2 && _context3.t2.code, config, request);
|
3435
|
+
case 39:
|
3421
3436
|
case "end":
|
3422
3437
|
return _context3.stop();
|
3423
3438
|
}
|
3424
|
-
}, _callee3, null, [[4,
|
3439
|
+
}, _callee3, null, [[4, 33]]);
|
3425
3440
|
}));
|
3426
3441
|
return function (_x4) {
|
3427
3442
|
return _ref3.apply(this, arguments);
|
@@ -3545,7 +3560,7 @@
|
|
3545
3560
|
});
|
3546
3561
|
}
|
3547
3562
|
|
3548
|
-
var VERSION = "1.7.0
|
3563
|
+
var VERSION = "1.7.0";
|
3549
3564
|
|
3550
3565
|
var validators$1 = {};
|
3551
3566
|
|