diff --git a/fetch.js b/fetch.js index 37b98218..c4162dae 100644 --- a/fetch.js +++ b/fetch.js @@ -162,6 +162,7 @@ if (support.iterable) { } function consumed(body) { + if (body._noBody) return if (body.bodyUsed) { return Promise.reject(new TypeError('Already read')) } @@ -231,6 +232,7 @@ function Body() { this.bodyUsed = this.bodyUsed this._bodyInit = body if (!body) { + this._noBody = true; this._bodyText = '' } else if (typeof body === 'string') { this._bodyText = body diff --git a/test/test.js b/test/test.js index d6431f40..8508610b 100644 --- a/test/test.js +++ b/test/test.js @@ -996,6 +996,15 @@ exercise.forEach(function(exerciseMode) { 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() + }) }) })