Skip to content

Header.forEach inconsistent with standard fetch API #1072

@lquixada

Description

@lquixada

Hi this is the cross-fetch author. In order to keep maximum consistency between node-fetch, whatwg-fetch and native browser fetch, I'm running the same suite of tests across all these implementations. For the 3.0.0-beta.9 version, there are only two issues with Headers' forEach method that differs from browsers' fetch and whatwg-fetch:

  1. It does not accept thisArg as the second parameter
  2. The callback does not provide a third argument: the header object itself.

Here's a code to illustrate that:

const headers = new Headers()
headers.append('Accept', 'application/json')

const obj = {}
const results = []
headers.forEach(function (value, key, object) {
  results.push({ value, key, object, thisArg: this })
}, obj);

console.log(results[0].object === headers) // true on browser, false on node-fetch 3.0.0-beta.9
console.log(results[0].thisArg === obj) // true on browser, false on node-fetch 3.0.0-beta.9

I realize that on version 2.6.1, it used to have both features. So my question: is this intentional? If not, does anyone mind if I open a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions