Skip to content

Commit

Permalink
Allow reusing the same GET Request instance multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Nov 10, 2016
1 parent 80105ae commit 94a598a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
}
this.method = input.method
this.mode = input.mode
if (!body) {
if (!body && input._bodyInit != null) {
body = input._bodyInit
input.bodyUsed = true
}
Expand Down
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,33 @@ suite('fetch method', function() {
})
})

test('reusing same Request multiple times', function() {
var request = new Request('/request', {
headers: {
'Accept': 'application/json',
'X-Test': '42'
}
})

var responses = []

return fetch(request).then(function(response) {
responses.push(response)
return fetch(request)
}).then(function(response) {
responses.push(response)
return fetch(request)
}).then(function(response) {
responses.push(response)
return Promise.all(responses.map(function(r) { return r.json() }))
}).then(function(jsons) {
jsons.forEach(function(json) {
assert.equal(json.headers['accept'], 'application/json')
assert.equal(json.headers['x-test'], '42')
})
})
})

featureDependent(test, support.arrayBuffer, 'sends ArrayBuffer body', function() {
return fetch('/request', {
method: 'post',
Expand Down

0 comments on commit 94a598a

Please sign in to comment.