Skip to content

Commit 4098943

Browse files
committed
fix: Default to allow node to handle connection keepalive. Fixes node-fetch#1735
1 parent 7b86e94 commit 4098943

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ If no values are set, the following request headers will be sent automatically:
539539
| ------------------- | ------------------------------------------------------ |
540540
| `Accept-Encoding` | `gzip, deflate, br` (when `options.compress === true`) |
541541
| `Accept` | `*/*` |
542-
| `Connection` | `close` _(when no `options.agent` is present)_ |
543542
| `Content-Length` | _(automatically calculated, if possible)_ |
544543
| `Host` | _(host and port information from the target URI)_ |
545544
| `Transfer-Encoding` | `chunked` _(when `req.body` is a stream)_ |
@@ -558,6 +557,8 @@ The `agent` option allows you to specify networking related options which are ou
558557

559558
See [`http.Agent`](https://nodejs.org/api/http.html#http_new_agent_options) for more information.
560559

560+
If no agent is specified, the default agaent provided by Node.js is used. Note that [this changed in Node.js 19](https://github.com/nodejs/node/blob/4267b92604ad78584244488e7f7508a690cb80d0/lib/_http_agent.js#L564) to have `keepalive` true by default.
561+
561562
In addition, the `agent` option accepts a function that returns `http`(s)`.Agent` instance given current [URL](https://nodejs.org/api/url.html), this is useful during a redirection chain across HTTP and HTTPS protocol.
562563

563564
```js

src/request.js

-4
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ export const getNodeRequestOptions = request => {
288288
agent = agent(parsedURL);
289289
}
290290

291-
if (!headers.has('Connection') && !agent) {
292-
headers.set('Connection', 'close');
293-
}
294-
295291
// HTTP-network fetch step 4.2
296292
// chunked encoding is handled by Node.js
297293

0 commit comments

Comments
 (0)