Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var support = {
}
})(),
formData: 'FormData' in g,
arrayBuffer: 'ArrayBuffer' in g
arrayBuffer: 'ArrayBuffer' in g,
headers: 'Headers' in g && g.Headers,
}

function isDataView(obj) {
Expand Down Expand Up @@ -86,7 +87,7 @@ function iteratorFor(items) {
export function Headers(headers) {
this.map = {}

if (headers instanceof Headers) {
if (headers instanceof Headers || (support.headers && headers instanceof support.headers)) {
headers.forEach(function(value, name) {
this.append(name, value)
}, this)
Expand Down
13 changes: 12 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var support = {
formData: 'FormData' in self,
arrayBuffer: 'ArrayBuffer' in self,
aborting: 'signal' in new Request(''),
permanentRedirect: !/Trident/.test(navigator.userAgent)
permanentRedirect: !/Trident/.test(navigator.userAgent),
headers: 'Headers' in self && self.Headers,
}

function readBlobAsText(blob) {
Expand Down Expand Up @@ -214,6 +215,16 @@ exercise.forEach(function(exerciseMode) {
])
}, TypeError)
})
featureDependent(test, support.headers, 'constructor copies headers from native Headers', function() {
var original = new support.headers()
original.append('Accept', 'application/json')
original.append('Accept', 'text/plain')
original.append('Content-Type', 'text/html')

var headers = new Headers(original)
assert.equal(headers.get('Accept'), 'application/json, text/plain')
assert.equal(headers.get('Content-type'), 'text/html')
})
test('headers are case insensitive', function() {
var headers = new Headers({Accept: 'application/json'})
assert.equal(headers.get('ACCEPT'), 'application/json')
Expand Down