axios 0.33.0 → 0.35.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,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased — next v0 minor
4
+
5
+ These changes improve error handling, cancellation context, and request header typing.
6
+
7
+ ### ⚠️ Breaking Changes & Deprecations
8
+
9
+ * **Header types:** TypeScript now rejects header values that are Promises, functions, or objects with custom `toString()` methods. Resolve promises, call functions, or explicitly convert objects before assigning header values. This narrows previously accepted types and must ship in the next v0 minor release under the pre-1.0 compatibility policy. (__#11209__)
10
+
11
+ ### 🚀 New Features
12
+
13
+ * **Caller diagnostics:** Opt in with `captureCallerStack: true` on a request or instance to append caller frames to asynchronous errors. The default is off so successful requests avoid the additional stack capture and Promise reaction. (__#11209__)
14
+ * **Cancellation context:** `CanceledError.reason` preserves `AbortSignal.reason`, including object and falsy values. Native and structural signals retain their identity and live getters across config merging. (__#11209__)
15
+
16
+ ### 🐛 Bug Fixes
17
+
18
+ * **Error inheritance:** Axios loads alongside read-only `Error.prototype.toJSON` properties while preserving supplied own descriptors and setters. (__#11209__)
19
+ * **Request interceptors:** Synchronous interceptor and dispatch failures reach response interceptors. Rejected recovery promises prevent dispatch; fulfilled recovery values are ignored and the last request config is retained. (__#11209__)
20
+
21
+ [Full Changelog](https://github.com/axios/axios/pull/11209/files)
22
+
3
23
  ## v0.32.0 — May 4, 2026
4
24
 
5
25
  This release backports a comprehensive set of security and hardening fixes from the v1.x branch into v0.x, covering prototype-pollution protections, default error redaction, stricter proxy/cookie/socket handling, and one breaking change to merged config and header object prototypes.
package/README.md CHANGED
@@ -494,7 +494,13 @@ These are the available config options for making requests. Only the `url` is re
494
494
  // supplies credentials.
495
495
  // This will set an `Proxy-Authorization` header, overwriting any existing
496
496
  // `Proxy-Authorization` custom headers you have set using `headers`.
497
- // If the proxy server uses HTTPS, then you must set the protocol to `https`.
497
+ // Set the protocol to `http` for a plaintext proxy or `https` for a TLS proxy.
498
+ // HTTP(S) schemes accept a trailing colon, any case, and surrounding whitespace.
499
+ // If omitted, the proxy connection inherits the target URL's protocol.
500
+ // Empty strings and non-string values also leave the target protocol unchanged.
501
+ // A plaintext proxy for an HTTPS target therefore requires explicit `http`.
502
+ // Unsupported non-empty strings (e.g. `ftp`, `https://`, or whitespace-only)
503
+ // reject with `ERR_BAD_OPTION_VALUE` before connecting, without a fallback.
498
504
  proxy: {
499
505
  protocol: 'https',
500
506
  host: '127.0.0.1',
@@ -513,6 +519,10 @@ These are the available config options for making requests. Only the `url` is re
513
519
  // an alternative way to cancel Axios requests using AbortController
514
520
  signal: new AbortController().signal,
515
521
 
522
+ // Capture the request caller for asynchronous error stacks (default: false).
523
+ // Enable on a request or instance when the extra diagnostics are needed.
524
+ captureCallerStack: false,
525
+
516
526
  // `decompress` indicates whether or not the response body should be decompressed
517
527
  // automatically. If set to `true` will also remove the 'content-encoding' header
518
528
  // from the responses objects of all decompressed responses
@@ -742,8 +752,31 @@ and when the response was fulfilled
742
752
 
743
753
  Read [the interceptor tests](./test/specs/interceptors.spec.js) for seeing all this in code.
744
754
 
755
+ For synchronous request interceptors, a thrown error is passed to that interceptor's
756
+ rejection handler, when supplied. If the handler is absent, throws, or returns a
757
+ rejected promise, the request is rejected without being sent and response rejection
758
+ interceptors can handle the failure. A promise returned by a recovery handler is
759
+ awaited before dispatch. Recovery return values, including fulfilled promise values,
760
+ do not replace the last request config; that config is used for dispatch.
761
+ Successful synchronous interceptors still dispatch immediately.
762
+
745
763
  ## Handling Errors
746
764
 
765
+ Set `captureCallerStack: true` on a request or instance to append the original caller
766
+ to errors created asynchronously. Stack capture is disabled by default because it
767
+ adds work to every enabled request, including successful requests. When disabled,
768
+ Axios keeps the error's existing stack without capturing additional caller frames.
769
+
770
+ ```js
771
+ const client = axios.create({captureCallerStack: true});
772
+ client.get('/user/12345');
773
+ // An individual request can override the instance setting.
774
+ client.get('/status', {captureCallerStack: false});
775
+ ```
776
+
777
+ The original error and its existing stack are preserved when caller frames are
778
+ appended. Availability and frame counts depend on the runtime's stack support and settings.
779
+
747
780
  ```js
748
781
  axios.get('/user/12345')
749
782
  .catch(function (error) {
@@ -803,6 +836,26 @@ axios.get('/foo/bar', {
803
836
  controller.abort()
804
837
  ```
805
838
 
839
+ On runtimes that expose `AbortSignal.reason`, Axios preserves that value in
840
+ `CanceledError.reason`, including objects and falsy values. Cancellation still uses
841
+ the `canceled` message, `ERR_CANCELED` code, and `axios.isCancel()` detection. Signals
842
+ without a reason continue to work and leave `error.reason` undefined.
843
+ Native signals and plain objects implementing `GenericAbortSignal` are retained by
844
+ reference when configurations are merged, preserving live getters and reason identity.
845
+
846
+ ```js
847
+ const controller = new AbortController();
848
+ const reason = new Error('Replaced by a newer search');
849
+
850
+ axios.get('/search', {signal: controller.signal}).catch(function (error) {
851
+ if (axios.isCancel(error) && error.reason === reason) {
852
+ // This request was superseded.
853
+ }
854
+ });
855
+
856
+ controller.abort(reason);
857
+ ```
858
+
806
859
  ### CancelToken `👎deprecated`
807
860
 
808
861
  You can also cancel a request using a *CancelToken*.
@@ -1181,6 +1234,22 @@ If your environment doesn't support ES6 Promises, you can [polyfill](https://git
1181
1234
 
1182
1235
  ## TypeScript
1183
1236
 
1237
+ Request header values are strings, string arrays, numbers, or booleans. The
1238
+ `common` and method-specific header groups accept maps of these values. Resolve
1239
+ asynchronous values in a request interceptor before assigning them to headers;
1240
+ Promise and function values are rejected by the TypeScript declarations.
1241
+
1242
+ This is a TypeScript compatibility change for the next v0 minor release. Code that
1243
+ previously assigned a Promise, function, or object with a custom `toString()` method
1244
+ must first resolve the Promise, call the function, or explicitly convert the object
1245
+ to a supported header value. For example:
1246
+
1247
+ ```typescript
1248
+ async function requestWithToken(token: Promise<string>) {
1249
+ return axios.get('/user', {headers: {Authorization: 'Bearer ' + await token}});
1250
+ }
1251
+ ```
1252
+
1184
1253
  axios includes [TypeScript](https://typescriptlang.org) definitions and a type guard for axios errors.
1185
1254
 
1186
1255
  ```typescript