axios 1.13.6 β†’ 1.15.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
@@ -180,7 +180,7 @@
180
180
 
181
181
  ### Bug Fixes
182
182
 
183
- - form-data npm pakcage ([#6970](https://github.com/axios/axios/issues/6970)) ([e72c193](https://github.com/axios/axios/commit/e72c193722530db538b19e5ddaaa4544d226b253))
183
+ - form-data npm package ([#6970](https://github.com/axios/axios/issues/6970)) ([e72c193](https://github.com/axios/axios/commit/e72c193722530db538b19e5ddaaa4544d226b253))
184
184
  - prevent RangeError when using large Buffers ([#6961](https://github.com/axios/axios/issues/6961)) ([a2214ca](https://github.com/axios/axios/commit/a2214ca1bc60540baf2c80573cea3a0ff91ba9d1))
185
185
  - **types:** resolve type discrepancies between ESM and CJS TypeScript declaration files ([#6956](https://github.com/axios/axios/issues/6956)) ([8517aa1](https://github.com/axios/axios/commit/8517aa16f8d082fc1d5309c642220fa736159110))
186
186
 
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ <h3 align="center"> πŸ’Ž Platinum sponsors <br> </h3> <table align="center"><tr><td align="center" width="50%"> <a href="https://thanks.dev/?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="90px" height="90px" src="https://axios-http.com/assets/sponsors/opencollective/ed51c2ee8f1b70aa3484d6dd678652134079a036.png" alt="THANKS.DEV"/> </a> <p align="center" title="We&#x27;re passionate about making open source sustainable. Scan your dependancy tree to better understand which open source projects need funding the most. Maintainers can also register their projects to become eligible for funding.">We&#x27;re passionate about making open source sustainable. Scan your dependancy tree to better understand which open source projects need funding the...</p> <p align="center"> <a href="https://thanks.dev/?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship" target="_blank"><b>thanks.dev</b></a> </p>
2
+ </td><td align="center" width="50%"> <a href="https://opencollective.com/hopper-security?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="90px" height="90px" src="https://axios-http.com/assets/sponsors/opencollective/180d02a83ee99448f850e39eed6dbb95f56000ba.png" alt="Hopper Security"/> </a> <p align="center"> </p>
3
+ </td></tr></table><table align="center"><tr><td align="center" width="50%"> <a href="https://opencollective.com/axios/contribute" target="_blank" >πŸ’œ Become a sponsor</a>
4
+ </td><td align="center" width="50%"> <a href="https://opencollective.com/axios/contribute" target="_blank" >πŸ’œ Become a sponsor</a>
5
+ </td></tr></table>
1
6
  <h3 align="center"> πŸ₯‡ Gold sponsors <br> </h3> <table align="center" width="100%"><tr width="33.333333333333336%"><td align="center" width="33.333333333333336%"> <a href="https://www.principal.com/about-us?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="133px" height="43px" src="https://axios-http.com/assets/sponsors/principal.svg" alt="Principal Financial Group"/> </a> <p align="center" title="We’re bound by one common purpose: to give you the financial tools, resources and information you need to live your best life.">We’re bound by one common purpose: to give you the financial tools, resources and information you ne...</p> <p align="center"> <a href="https://www.principal.com/about-us?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship" target="_blank"><b>www.principal.com</b></a> </p>
2
7
  </td><td align="center" width="33.333333333333336%"> <a href="https://twicsy.com/buy-instagram-followers?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="85px" height="70px" src="https://axios-http.com/assets/sponsors/opencollective/dfa9670ad5e66eea17315332453c7f4e3a3b5905.png" alt="Buy Instagram Followers Twicsy"/> </a> <p align="center" title="Buy real Instagram followers from Twicsy starting at only $2.97. Twicsy has been voted the best site to buy followers from the likes of US Magazine.">Buy real Instagram followers from Twicsy starting at only $2.97. Twicsy has been voted the best site...</p> <p align="center"> <a href="https://twicsy.com/buy-instagram-followers?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship" target="_blank"><b>twicsy.com</b></a> </p>
3
8
  </td><td align="center" width="33.333333333333336%"> <a href="https://www.descope.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;referral&amp;utm_campaign&#x3D;axios-oss-sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <picture> <source width="200px" height="52px" media="(prefers-color-scheme: dark)" srcset="https://axios-http.com/assets/sponsors/descope_white.png"> <img width="200px" height="52px" src="https://axios-http.com/assets/sponsors/descope.png" alt="Descope"/> </picture> </a> <p align="center" title="Hi, we&#x27;re Descope! We are building something in the authentication space for app developers and can’t wait to place it in your hands.">Hi, we&#x27;re Descope! We are building something in the authentication space for app developers and...</p> <p align="center"> <a href="https://www.descope.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;referral&amp;utm_campaign&#x3D;axios-oss-sponsorship" target="_blank"><b>Website</b></a> | <a href="https://docs.descope.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;referral&amp;utm_campaign&#x3D;axios-oss-sponsorship" target="_blank"><b>Docs</b></a> | <a href="https://www.descope.com/community?utm_source&#x3D;axios&amp;utm_medium&#x3D;referral&amp;utm_campaign&#x3D;axios-oss-sponsorship" target="_blank"><b>Community</b></a> </p>
@@ -5,7 +10,7 @@
5
10
  </td><td align="center" width="33.333333333333336%"> <a href="https://buzzoid.com/buy-instagram-followers/?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="62px" height="70px" src="https://axios-http.com/assets/sponsors/opencollective/e1625cb54e10ee40180c99d1495a462e9d6664a4.png" alt="Buzzoid - Buy Instagram Followers"/> </a> <p align="center" title="At Buzzoid, you can buy Instagram followers quickly, safely, and easily with just a few clicks. Rated world&#x27;s #1 IG service since 2012.">At Buzzoid, you can buy Instagram followers quickly, safely, and easily with just a few clicks. Rate...</p> <p align="center"> <a href="https://buzzoid.com/buy-instagram-followers/?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship" target="_blank"><b>buzzoid.com</b></a> </p>
6
11
  </td><td align="center" width="33.333333333333336%"> <a href="https://poprey.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="70px" height="70px" src="https://axios-http.com/assets/sponsors/opencollective/e699ec99f7df3a203ddbc49d3c7712a907e628ea.png" alt="Poprey - Buy Instagram Likes"/> </a> <p align="center" title="Buy Instagram Likes">Buy Instagram Likes</p> <p align="center"> <a href="https://poprey.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship" target="_blank"><b>poprey.com</b></a> </p>
7
12
  </td></tr><tr width="33.333333333333336%"><td align="center" width="33.333333333333336%"> <a href="https://requestly.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship" style="padding: 10px; display: inline-block" target="_blank"> <img width="71px" height="70px" src="https://axios-http.com/assets/sponsors/opencollective/16450b4dc0deb9dab5a511bf2bc8b8b4ac33412f.png" alt="Requestly"/> </a> <p align="center" title="A lightweight open-source API Development, Testing &amp; Mocking platform">A lightweight open-source API Development, Testing &amp; Mocking platform</p> <p align="center"> <a href="https://requestly.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship" target="_blank"><b>requestly.com</b></a> </p>
8
- </td><td align="center" width="33.333333333333336%"> <a href="https://opencollective.com/axios/contribute" target="_blank" >πŸ’œ Become a sponsor</a>
13
+ </td><td align="center" width="33.333333333333336%"> <a href="https://rxdb.info/?utm_source&#x3D;opencollective&amp;utm_medium&#x3D;banner&amp;utm_campaign&#x3D;opencollective_sponsor&amp;utm_content&#x3D;logo" style="padding: 10px; display: inline-block" target="_blank"> <img width="158px" height="70px" src="https://axios-http.com/assets/sponsors/opencollective/b28cc6ed919b414cb5f3d4a6d666cb8e06c5ff07.png" alt="RxDB"/> </a> <p align="center" title="RxDB is a fast, local-first NoSQL-database for JavaScript Applications like Websites, hybrid Apps, Electron-Apps, Progressive Web Apps and Node.js">RxDB is a fast, local-first NoSQL-database for JavaScript Applications like Websites, hybrid Apps, E...</p> <p align="center"> <a href="https://rxdb.info/?utm_source&#x3D;opencollective&amp;utm_medium&#x3D;banner&amp;utm_campaign&#x3D;opencollective_sponsor&amp;utm_content&#x3D;logo" target="_blank"><b>rxdb.info</b></a> </p>
9
14
  </td><td align="center" width="33.333333333333336%"> <a href="https://opencollective.com/axios/contribute" target="_blank" >πŸ’œ Become a sponsor</a>
10
15
  </td></tr></table>
11
16
 
@@ -455,6 +460,8 @@ These are the available config options for making requests. Only the `url` is re
455
460
 
456
461
  // `withCredentials` indicates whether or not cross-site Access-Control requests
457
462
  // should be made using credentials
463
+ // This only controls whether the browser sends credentials.
464
+ // It does not control whether the XSRF header is added.
458
465
  withCredentials: false, // default
459
466
 
460
467
  // `adapter` allows custom handling of requests which makes testing easier.
@@ -494,9 +501,30 @@ These are the available config options for making requests. Only the `url` is re
494
501
  // `xsrfHeaderName` is the name of the http header that carries the xsrf token value
495
502
  xsrfHeaderName: 'X-XSRF-TOKEN', // default
496
503
 
504
+ // `withXSRFToken` defines whether to send the XSRF header in browser requests.
497
505
  // `undefined` (default) - set XSRF header only for the same origin requests
506
+ // `true` - always set XSRF header, including for cross-origin requests
507
+ // `false` - never set XSRF header
508
+ // function - resolve with custom logic; receives the internal config object
498
509
  withXSRFToken: boolean | undefined | ((config: InternalAxiosRequestConfig) => boolean | undefined),
499
510
 
511
+ // `withXSRFToken` controls whether Axios reads the XSRF cookie and sets the XSRF header.
512
+ // - `undefined` (default): the XSRF header is set only for same-origin requests.
513
+ // - `true`: attempt to set the XSRF header for all requests (including cross-origin).
514
+ // - `false`: never set the XSRF header.
515
+ // - function: a callback that receives the request `config` and returns `true`,
516
+ // `false`, or `undefined` to decide per-request behavior.
517
+ //
518
+ // Note about `withCredentials`: `withCredentials` controls whether cross-site
519
+ // requests include credentials (cookies and HTTP auth). In older Axios versions,
520
+ // setting `withCredentials: true` implicitly caused Axios to set the XSRF header
521
+ // for cross-origin requests. Newer Axios separates these concerns: to allow the
522
+ // XSRF header to be sent for cross-origin requests you should set both
523
+ // `withCredentials: true` and `withXSRFToken: true`.
524
+ //
525
+ // Example:
526
+ // axios.get('/user', { withCredentials: true, withXSRFToken: true });
527
+
500
528
  // `onUploadProgress` allows handling of progress events for uploads
501
529
  // browser & node.js
502
530
  onUploadProgress: function ({loaded, total, progress, bytes, estimated, rate, upload = true}) {
@@ -532,11 +560,27 @@ These are the available config options for making requests. Only the `url` is re
532
560
  // to inspect the latest response headers,
533
561
  // or to cancel the request by throwing an error
534
562
  // If maxRedirects is set to 0, `beforeRedirect` is not used.
563
+
535
564
  beforeRedirect: (options, { headers }) => {
536
- if (options.hostname === "example.com") {
565
+ if (
566
+ options.hostname === "example.com" &&
567
+ options.protocol === "https:"
568
+ ) {
537
569
  options.auth = "user:password";
538
570
  }
539
571
  },
572
+ // Security note:
573
+ // The `beforeRedirect` hook runs after sensitive headers are stripped during redirects.
574
+ //The `follow-redirects` library removes credentials on protocol downgrade (HTTPS β†’ HTTP) for security.
575
+ //Since `beforeRedirect` runs after this, re-injecting credentials without checking the protocol can expose sensitive data.
576
+ //Always ensure credentials are only added for trusted HTTPS destinations.
577
+
578
+ // Security note:
579
+ // The beforeRedirect hook runs after sensitive headers are stripped during redirects.
580
+ // Re-injecting credentials without checking the destination can expose sensitive data.
581
+ // Only add credentials for trusted HTTPS destinations.
582
+ // Avoid re-adding credentials on downgraded redirects.
583
+
540
584
 
541
585
  // `socketPath` defines a UNIX Socket to be used in node.js.
542
586
  // e.g. '/var/run/docker.sock' to send requests to the docker daemon.
@@ -607,7 +651,12 @@ These are the available config options for making requests. Only the `url` is re
607
651
  transitional: {
608
652
  // silent JSON parsing mode
609
653
  // `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
610
- // `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
654
+ // `false` - throw SyntaxError if JSON parsing failed
655
+ // Important: this option only takes effect when `responseType` is explicitly set to 'json'.
656
+ // When `responseType` is omitted (defaults to no value), axios uses `forcedJSONParsing`
657
+ // to attempt JSON parsing, but will silently return the raw string on failure regardless
658
+ // of this setting. To have invalid JSON throw errors, use:
659
+ // { responseType: 'json', transitional: { silentJSONParsing: false } }
611
660
  silentJSONParsing: true, // default value for the current Axios version
612
661
 
613
662
  // try to parse the response string as JSON even if `responseType` is not 'json'
@@ -639,6 +688,15 @@ These are the available config options for making requests. Only the `url` is re
639
688
  ]
640
689
  }
641
690
  ```
691
+ ## πŸ”₯ HTTP/2 Support
692
+
693
+ Axios has experimental HTTP/2 support available via the Node.js HTTP adapter.
694
+
695
+ Support depends on the runtime environment and Node.js version. Features like redirects and some behaviors may not be fully supported with HTTP/2.
696
+
697
+ Options like `httpVersion` and `http2Options` are adapter-specific and may not work consistently across all environments.
698
+
699
+ If HTTP/2 functionality is required, ensure your runtime environment supports it or consider using alternative libraries or custom adapters.
642
700
 
643
701
  ## Response Schema
644
702
 
@@ -969,15 +1027,25 @@ async function fetchWithTimeout() {
969
1027
  try {
970
1028
  const response = await axios.get("https://example.com/data", {
971
1029
  timeout: 5000, // 5 seconds
1030
+ transitional: {
1031
+ // set to true if you prefer ETIMEDOUT over ECONNABORTED
1032
+ clarifyTimeoutError: false,
1033
+ },
972
1034
  });
973
1035
 
974
1036
  console.log("Response:", response.data);
975
1037
  } catch (error) {
976
- if (axios.isAxiosError(error) && error.code === "ECONNABORTED") {
977
- console.error("❌ Request timed out!");
978
- } else {
979
- console.error("❌ Error:", error.message);
1038
+ if (axios.isAxiosError(error)) {
1039
+ if (error.code === "ECONNABORTED" || error.code === "ETIMEDOUT") {
1040
+ console.error("Request timed out. Please try again.");
1041
+ return;
1042
+ }
1043
+
1044
+ console.error("Axios error:", error.message);
1045
+ return;
980
1046
  }
1047
+
1048
+ console.error("Unexpected error:", error);
981
1049
  }
982
1050
  }
983
1051
  ```
@@ -1528,6 +1596,38 @@ for (const [header, value] of headers) {
1528
1596
  // baz 3
1529
1597
  ```
1530
1598
 
1599
+ ### Preserving a specific header case
1600
+
1601
+ Header names are case-insensitive, but `AxiosHeaders` keeps the case of the first matching key it sees.
1602
+ If you need a specific case for non-standard case-sensitive servers, define a case preset with `undefined` and then set the value later:
1603
+
1604
+ ```js
1605
+ const api = axios.create();
1606
+
1607
+ api.defaults.headers.common = {
1608
+ 'content-type': undefined,
1609
+ accept: undefined,
1610
+ };
1611
+
1612
+ await api.put(url, data, {
1613
+ headers: {
1614
+ 'Content-Type': 'application/octet-stream',
1615
+ Accept: 'application/json',
1616
+ },
1617
+ });
1618
+ ```
1619
+
1620
+ You can also compose the same behavior with `AxiosHeaders.concat`:
1621
+
1622
+ ```js
1623
+ const headers = axios.AxiosHeaders.concat(
1624
+ { 'content-type': undefined },
1625
+ { 'Content-Type': 'application/octet-stream' }
1626
+ );
1627
+
1628
+ await axios.put(url, data, { headers });
1629
+ ```
1630
+
1531
1631
  ### new AxiosHeaders(headers?)
1532
1632
 
1533
1633
  Constructs a new `AxiosHeaders` instance.
@@ -1818,12 +1918,15 @@ export async function load({ fetch }) {
1818
1918
  }
1819
1919
  ```
1820
1920
 
1821
- ## πŸ”₯ HTTP2
1921
+ #### HTTP/2 Support
1922
+
1923
+ Axios supports HTTP/2 via the Node.js `http` adapter (introduced in v1.13.0).
1924
+
1925
+ This support depends on the runtime environment. Since Axios relies on Node.js APIs, HTTP/2 functionality is available in supported Node.js versions, but may not work in other environments (such as Bun or Deno).
1822
1926
 
1823
- In version `1.13.0`, experimental `HTTP2` support was added to the `http` adapter.
1824
- The `httpVersion` option is now available to select the protocol version used.
1825
- Additional native options for the internal `session.request()` call can be passed via the `http2Options` config.
1826
- This config also includes the custom `sessionTimeout` parameter, which defaults to `1000ms`.
1927
+ Options like `httpVersion` and `http2Options` are adapter-specific and may not behave consistently across all environments.
1928
+
1929
+ Note: HTTP/2 redirects are currently not supported by the HTTP/2 adapter.
1827
1930
 
1828
1931
  ```js
1829
1932
  const form = new FormData();
@@ -1834,11 +1937,6 @@ const { data, headers, status } = await axios.post(
1834
1937
  "https://httpbin.org/post",
1835
1938
  form,
1836
1939
  {
1837
- httpVersion: 2,
1838
- http2Options: {
1839
- // rejectUnauthorized: false,
1840
- // sessionTimeout: 1000
1841
- },
1842
1940
  onUploadProgress(e) {
1843
1941
  console.log("upload progress", e);
1844
1942
  },
@@ -1846,7 +1944,7 @@ const { data, headers, status } = await axios.post(
1846
1944
  console.log("download progress", e);
1847
1945
  },
1848
1946
  responseType: "arraybuffer",
1849
- },
1947
+ }
1850
1948
  );
1851
1949
  ```
1852
1950