Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add example for request + "Garbage Collection" #3916

Merged
merged 5 commits into from
Dec 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ const headers = await fetch(url)
.then(res => res.headers)
```

The same applies for `request` too:
```js
// Do
const response = await request(url)
.then(res => {
response.body.dump().catch(err => {
console.error('Error while dumping the body');
WTCT-TOP marked this conversation as resolved.
Show resolved Hide resolved
});
return res.headers;
});

// Do not
const response = await request(url)
.then(res => res.headers);
```

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.

```js
Expand Down