[whatwg/fetch] bodyUsed don't gets set properly (#396)

When working with github/fetch polyfill and building a test i found a tiny issue:

```javascript
rs = new ReadableStream({})
res = new Response(rs)
res.body.getReader()
console.log(res.bodyUsed) // false

try {
  res.clone() // throws Failed to execute 'clone' on 'Response': Response body is already used(…)
} catch (err) {
  console.log(res.bodyUsed) // still false
}

```

Think the bodyUsed flag should be set to true when you call getReader() ?

It's not until you call read() as the flag `bodyUsed` gets set to false
```javascript
rs = new ReadableStream({})
res = new Response(rs)
reader = res.body.getReader()
reader.read()
console.log(res.bodyUsed) // true
// body used (don't call clone())
```

Ended up doing something like this:
```javascript
// this == instance of Response
Object.defineProperty(this, 'bodyUsed', {
  enumerable: true,
  get: () => stream.locked
})
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/396

Received on Monday, 10 October 2016 15:50:40 UTC