Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: node-fetch/node-fetch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.6.12
Choose a base ref
...
head repository: node-fetch/node-fetch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.6.13
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Aug 18, 2023

  1. 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.
    dhedey authored Aug 18, 2023
    Copy the full SHA
    65ae25a View commit details
Showing with 2 additions and 5 deletions.
  1. +2 −1 README.md
  2. +0 −4 src/request.js
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -387,7 +387,6 @@ Header | Value
------------------- | --------------------------------------------------------
`Accept-Encoding` | `gzip,deflate` _(when `options.compress === true`)_
`Accept` | `*/*`
`Connection` | `close` _(when no `options.agent` is present)_
`Content-Length` | _(automatically calculated, if possible)_
`Transfer-Encoding` | `chunked` _(when `req.body` is a stream)_
`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

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

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.

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
4 changes: 0 additions & 4 deletions src/request.js
Original file line number Diff line number Diff line change
@@ -258,10 +258,6 @@ export function 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