From 53496ac17c7b777f5fd87540cc9fe862e9bf32df Mon Sep 17 00:00:00 2001 From: asrar211 <113281948+asrar211@users.noreply.github.com> Date: Fri, 20 Dec 2024 18:26:55 +0530 Subject: [PATCH] docs(fetch): add differences between Undici fetch and standard Fetch API --- docs/docs/api/Fetch.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/docs/api/Fetch.md b/docs/docs/api/Fetch.md index 00c349847dc..544abb53f8a 100644 --- a/docs/docs/api/Fetch.md +++ b/docs/docs/api/Fetch.md @@ -50,3 +50,21 @@ const busboy = new Busboy({ Readable.fromWeb(response.body).pipe(busboy) ``` + +## Differences Between Undici's Fetch and the Standard Fetch API + +The `fetch` implementation in Undici is inspired by the Fetch API standard but has some key differences: + +1. **`new Response(asyncIterable)`**: + - Undici extends the standard `Response` constructor to accept an `asyncIterable` as its body. This allows streams and other async sources to be directly used. This feature is not part of the Fetch API in browsers. + +2. **Cookies Handling**: + - Unlike browsers, Undici does not automatically manage cookies. In browsers, cookies are managed through the `Cookie` header and automatically sent with requests. In Undici, you need to manually handle cookies. + +3. **No Forbidden Headers**: + - In browsers, some headers (e.g., `User-Agent`, `Referer`) are restricted from being modified for security reasons. In Undici, these headers can be freely set. + +4. **Environment-Specific Behavior**: + - Undici operates outside of a browser environment, so browser-specific features like Service Workers and Cache API are unavailable. + +For a complete reference, see the [WHATWG Fetch Standard](https://fetch.spec.whatwg.org/). \ No newline at end of file