Skip to content

Commit

Permalink
Merge pull request JakeChampion#485 from tschaub/headers-array
Browse files Browse the repository at this point in the history
Accept array in Headers constructor
  • Loading branch information
dgraham authored Feb 22, 2017
2 parents 49e8030 + adc251c commit 9630aaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@
headers.forEach(function(value, name) {
this.append(name, value)
}, this)

} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1]);
}, this);
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name])
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ suite('Headers', function() {
assert.equal(headers.get('Accept'), 'application/json,text/plain')
assert.equal(headers.get('Content-type'), 'text/html')
})
test('constructor works with arrays', function() {
var array = [
['Content-Type', 'text/xml'],
['Breaking-Bad', '<3']
];
var headers = new Headers(array)

assert.equal(headers.get('Content-Type'), 'text/xml')
assert.equal(headers.get('Breaking-Bad'), '<3')
})
test('headers are case insensitive', function() {
var headers = new Headers({'Accept': 'application/json'})
assert.equal(headers.get('ACCEPT'), 'application/json')
Expand Down

0 comments on commit 9630aaa

Please sign in to comment.