Skip to content

Accept array in Headers constructor - #485

Merged
dgraham merged 1 commit into
JakeChampion:masterfrom
tschaub:headers-array
Feb 22, 2017
Merged

dgraham merged 1 commit into
JakeChampion:masterfrom
tschaub:headers-array

Conversation

@tschaub

@tschaub tschaub commented Feb 22, 2017

Copy link
Copy Markdown
Contributor

From the spec, it looks like the Headers constructor should accept an array of arrays.

I've adapted the example for the tests:

var meta = { "Content-Type": "text/xml", "Breaking-Bad": "<3" }
new Headers(meta)

// The above is equivalent to
var meta = [
  [ "Content-Type", "text/xml" ],
  [ "Breaking-Bad", "<3" ]
]
new Headers(meta)

This came up for me as an issue using stream-http in Edge with the Financial Times polyfill. I've opened jhiesey/stream-http#71 and polyfillpolyfill/polyfill-service#1091 in case this can be addressed elsewhere, but it looks to me like this might be the right fix.

@dgraham

dgraham commented Feb 22, 2017 •

Copy link
Copy Markdown
Contributor

The native Headers implementation in Chrome, Firefox, and Edge accepts an array in the constructor. IE 11 and Safari 10, where this polyfill is active, does not, so this is indeed a bug in the Headers polyfill.

Thanks for the detailed bug report and fix.

@mislav mislav left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! This looks good to me. @dgraham any reason why you didn't merge yet?

Comment thread fetch.js
} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1]);
}, this);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use semicolons.

@dgraham
dgraham merged commit 9630aaa into JakeChampion:master Feb 22, 2017
@tschaub
tschaub deleted the headers-array branch February 22, 2017 15:36
@tschaub

tschaub commented Mar 1, 2017

Copy link
Copy Markdown
Contributor Author

Thanks for pulling this in @dgraham. Any chance for an updated release with the fix?

@dgraham

dgraham commented Mar 2, 2017

Copy link
Copy Markdown
Contributor

The 2.0.3 release is now available on npm.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants