Skip to content

Commit 8b3320d

Browse files
authored
fix: Remove the default connection close header. (#1736)
Instead, we rely on the underlying http implementation in Node.js to handle this, as per the documentation at https://nodejs.org/api/http.html#new-agentoptions This fixes #1735 and likely replaces #1473 The original change introducing this provided no clear motivation for the override, and the implementation has since been changed to disable this header when an agent is provided, so I think there is sufficient evidence that removing this is the correct behaviour. af21ae6 7f68577
1 parent 7b86e94 commit 8b3320d

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
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 agent 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. If you wish to enable `keepalive` in an earlier version of Node.js, you can override the agent as per the following code sample.
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

Lines changed: 0 additions & 4 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy