diff --git a/README.md b/README.md index 890d82c2f7c..23891fe365d 100644 --- a/README.md +++ b/README.md @@ -281,17 +281,23 @@ stalls or deadlocks when running out of connections. ```js // Do -const headers = await fetch(url) - .then(async res => { - for await (const chunk of res.body) { - // force consumption of body - } - return res.headers - }) +const { body, headers } = await fetch(url); +for await (const chunk of body) { + // force consumption of body +} // Do not -const headers = await fetch(url) - .then(res => res.headers) +const { headers } = await fetch(url); +``` + +The same applies for `request` too: +```js +// Do +const { body, headers } = await request(url); +await res.body.dump(); // force consumption of body + +// Do not +const { headers } = await request(url); ``` However, if you want to get only headers, it might be better to use `HEAD` request method. Usage of this method will obviate the need for consumption or cancelling of the response body. See [MDN - HTTP - HTTP request methods - HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) for more details.