Skip to content

Commit 65ae25a

Browse files
authored
fix: Remove the default connection close header (#1765)
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 This commit is backported to the v2 branch from #1736 against v3.
1 parent 8bc3a7c commit 65ae25a

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
@@ -387,7 +387,6 @@ Header | Value
387387
------------------- | --------------------------------------------------------
388388
`Accept-Encoding` | `gzip,deflate` _(when `options.compress === true`)_
389389
`Accept` | `*/*`
390-
`Connection` | `close` _(when no `options.agent` is present)_
391390
`Content-Length` | _(automatically calculated, if possible)_
392391
`Transfer-Encoding` | `chunked` _(when `req.body` is a stream)_
393392
`User-Agent` | `node-fetch/1.0 (+https://github.com/bitinn/node-fetch)`
@@ -404,6 +403,8 @@ The `agent` option allows you to specify networking related options which are ou
404403

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

406+
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.
407+
407408
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.
408409

409410
```js

src/request.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,6 @@ export function getNodeRequestOptions(request) {
258258
agent = agent(parsedURL);
259259
}
260260

261-
if (!headers.has('Connection') && !agent) {
262-
headers.set('Connection', 'close');
263-
}
264-
265261
// HTTP-network fetch step 4.2
266262
// chunked encoding is handled by Node.js
267263

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