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
maxResponseSizeoption 0d59458- Limits the response body size in bytes, counted after decompression. Exceeding it throws the new
ResponseSizeError.
- Limits the response body size in bytes, counted after decompression. Exceeding it throws the new
- Let
beforeRetryhooks change options for the next attempts (#885) 242c327- Return
{options: {...}}to changeonUploadProgress,onDownloadProgress,timeout,fetch, orthrowHttpErrors. For example, retry a failed upload without upload progress.
- Return
- Respect
Retry-Afterand rate-limit headers whenretry.shouldRetryreturnstrued1c921f - Run
beforeErrorhooks for errors thrown while reading the response body 323b98f 50c3810- A connection that drops while
.json(),.text(), etc. reads the body is now aNetworkError.
- A connection that drops while
- Support
onUploadProgressand streamedRequestbodies in Bun and Deno 83c711c - Validate options and report clear errors 3ded2aa
- Invalid options now throw a
TypeErrorthat names the option, instead of being silently ignored or failing later with an internal error. This includesnull, non-array hooks, and invalidtimeoutandretryvalues. - Invalid options and errors thrown by
inithooks now reject the returned promise instead of throwing synchronously.
- Invalid options now throw a
- Improve TypeScript types 51b3177 52b8f93 f4886ca 481f6f7
- Accept readonly arrays and explicit
undefinedfor all options, allow custom error names, and fix the.clone()and.bytes()return types.
- Accept readonly arrays and explicit
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
NetworkErrorand retried in Chromium.totalTimeoutis now enforced when the response or body arrives after the deadline.
- User aborts and timeouts now also cancel requests returned from hooks, interrupt pending hooks and body reads, and are no longer reported as
- Fix
searchParamswith aRequestinput dropping its body and options such ascredentialsb4bdecc 4e0bf0b - Fix option merging in
.extend()andinithooks e06d351 0655b9d c5dc4e6 88e2432- Class instances, such as an undici
Agentasdispatcheror aDateinjson, are no longer turned into plain objects. Header names are now matched case-insensitively. Changes made in.extend()callbacks andinithooks no longer leak into other requests.
- Class instances, such as an undici
- Fix many
replaceOption()edge cases cc9b5a3 d6e049a deb5a33 - Fix
parseJsonbeing ignored byresponse.clone().json()and when usingonDownloadProgressc6c5dbf 015ef95 - Fix progress events, including wrong
totalBytesfor compressed responses and missing response properties withonDownloadProgressd89c8c8 e893f16 de278ae - Fix
onUploadProgressbreaking uploads without request stream support, andkeepaliveandno-corsrequests 6520f64 06ebf18 - Fix
fetch: window.fetchthrowing "Illegal invocation" in browsers 92ef60e - Fix
isTimeoutError()and the other type guards matching unrelated errors with the samenamed636438 - Fix
requeston Ky errors being an internal clone instead of the request that was sent 619c427 ec3d17f