Skip to content

Commit

Permalink
fix: Default to allow node to handle connection keepalive. Fixes node…
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Apr 21, 2023
1 parent 7b86e94 commit 4098943
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ If no values are set, the following request headers will be sent automatically:
| ------------------- | ------------------------------------------------------ |
| `Accept-Encoding` | `gzip, deflate, br` (when `options.compress === true`) |
| `Accept` | `*/*` |
| `Connection` | `close` _(when no `options.agent` is present)_ |
| `Content-Length` | _(automatically calculated, if possible)_ |
| `Host` | _(host and port information from the target URI)_ |
| `Transfer-Encoding` | `chunked` _(when `req.body` is a stream)_ |
Expand All @@ -558,6 +557,8 @@ The `agent` option allows you to specify networking related options which are ou

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

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.

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.

```js
Expand Down
4 changes: 0 additions & 4 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ export const getNodeRequestOptions = request => {
agent = agent(parsedURL);
}

if (!headers.has('Connection') && !agent) {
headers.set('Connection', 'close');
}

// HTTP-network fetch step 4.2
// chunked encoding is handled by Node.js

Expand Down

0 comments on commit 4098943

Please sign in to comment.