Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior for headers with native Fetch API #1235

Closed
loderunner opened this issue Jan 12, 2023 · 0 comments · Fixed by #1360
Closed

Inconsistent behavior for headers with native Fetch API #1235

loderunner opened this issue Jan 12, 2023 · 0 comments · Fixed by #1360

Comments

@loderunner
Copy link

loderunner commented Jan 12, 2023

According to the Fetch documentation on MDN, the headers property of the options parameter can be:

a Headers object or an object literal with String values.

However, according to an example for errors below, an array of arrays of strings can be accepted (provided the inner arrays are of length 2).

Invalid header value. The header object must contain exactly two elements.

const headers = [
  ['Content-Type', 'text/html', 'extra'],
  ['Accept'],
];
fetch('https://example.com/', { headers });

This header initializer option is supported by the Headers constructor parameter, which can be

a simple object literal with String values, an array of name-value pairs, where each pair is a 2-element string array; or an existing Headers object.


Testing in Chrome 109.0.5414.87, I found an inconsistency between what is supported by whatwg-fetch and what is supported by Chrome's native Fetch API.

  • Chrome Fetch:
    • Object
    • Array
    • Chrome Fetch Headers class
    • whatwg-fetch Headers class
  • whatwg-fetch:
    • Object
    • whatwg-fetch Headers class

I found the same results for:

  • Safari 16.0 (17614.1.25.9.10, 17614)
  • Firefox 108.0.2

My test bench for Headers support is here. cross-fetch is also tested, as it relies on whatwg-fetch in the browser, yields yet another behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant