提交 7d92dff1 编写于 作者: J Jake Champion 提交者: Jake Champion

fix: when no body supplied, do not set bodyUsed to true

上级 0c1d2b97
...@@ -162,6 +162,7 @@ if (support.iterable) { ...@@ -162,6 +162,7 @@ if (support.iterable) {
} }
function consumed(body) { function consumed(body) {
if (body._noBody) return
if (body.bodyUsed) { if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read')) return Promise.reject(new TypeError('Already read'))
} }
...@@ -231,6 +232,7 @@ function Body() { ...@@ -231,6 +232,7 @@ function Body() {
this.bodyUsed = this.bodyUsed this.bodyUsed = this.bodyUsed
this._bodyInit = body this._bodyInit = body
if (!body) { if (!body) {
this._noBody = true;
this._bodyText = '' this._bodyText = ''
} else if (typeof body === 'string') { } else if (typeof body === 'string') {
this._bodyText = body this._bodyText = body
......
...@@ -996,6 +996,15 @@ exercise.forEach(function(exerciseMode) { ...@@ -996,6 +996,15 @@ exercise.forEach(function(exerciseMode) {
assert(error instanceof TypeError, 'Promise rejected after body consumed') assert(error instanceof TypeError, 'Promise rejected after body consumed')
}) })
}) })
test('does not set bodyUsed to true if no body supplied', function() {
var response = new Response();
assert(response.text, 'Body does not implement text')
assert.equal(response.bodyUsed, false)
response.text()
assert.equal(response.bodyUsed, false)
return response.text()
})
}) })
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册