Skip to content

v2.2.0

Latest

Choose a tag to compare

@sindresorhus sindresorhus released this 09 Oct 06:31

Note

In init hooks, options.headers now has lowercase names. Read and delete headers with lowercase names, for example delete options.headers.authorization.

Improvements

  • Add maxResponseSize option 0d59458
    • Limits the response body size in bytes, counted after decompression. Exceeding it throws the new ResponseSizeError.
  • Let beforeRetry hooks change options for the next attempts (#885) 242c327
    • Return {options: {...}} to change onUploadProgress, onDownloadProgress, timeout, fetch, or throwHttpErrors. For example, retry a failed upload without upload progress.
  • Respect Retry-After and rate-limit headers when retry.shouldRetry returns true d1c921f
  • Run beforeError hooks for errors thrown while reading the response body 323b98f 50c3810
    • A connection that drops while .json(), .text(), etc. reads the body is now a NetworkError.
  • Support onUploadProgress and streamed Request bodies in Bun and Deno 83c711c
  • Validate options and report clear errors 3ded2aa
    • Invalid options now throw a TypeError that names the option, instead of being silently ignored or failing later with an internal error. This includes null, non-array hooks, and invalid timeout and retry values.
    • Invalid options and errors thrown by init hooks now reject the returned promise instead of throwing synchronously.
  • Improve TypeScript types 51b3177 52b8f93 f4886ca 481f6f7
    • Accept readonly arrays and explicit undefined for all options, allow custom error names, and fix the .clone() and .bytes() return types.

Fixes

  • Fix aborts and timeouts in many edge cases e1b088e 2f0a3fb 7c1272b 82fa84c 3f0e330
    • User aborts and timeouts now also cancel requests returned from hooks, interrupt pending hooks and body reads, and are no longer reported as NetworkError and retried in Chromium. totalTimeout is now enforced when the response or body arrives after the deadline.
  • Fix searchParams with a Request input dropping its body and options such as credentials b4bdecc 4e0bf0b
  • Fix option merging in .extend() and init hooks e06d351 0655b9d c5dc4e6 88e2432
    • Class instances, such as an undici Agent as dispatcher or a Date in json, are no longer turned into plain objects. Header names are now matched case-insensitively. Changes made in .extend() callbacks and init hooks no longer leak into other requests.
  • Fix many replaceOption() edge cases cc9b5a3 d6e049a deb5a33
  • Fix parseJson being ignored by response.clone().json() and when using onDownloadProgress c6c5dbf 015ef95
  • Fix progress events, including wrong totalBytes for compressed responses and missing response properties with onDownloadProgress d89c8c8 e893f16 de278ae
  • Fix onUploadProgress breaking uploads without request stream support, and keepalive and no-cors requests 6520f64 06ebf18
  • Fix fetch: window.fetch throwing "Illegal invocation" in browsers 92ef60e
  • Fix isTimeoutError() and the other type guards matching unrelated errors with the same name d636438
  • Fix request on Ky errors being an internal clone instead of the request that was sent 619c427 ec3d17f

v2.1.0...v2.2.0