Re: [ServiceWorker] Backpressure on fetch integrated with Streams (#452)

yutakahirano@
> I heard that cache.put and respondWith want to assume that no bytes are read from the body, from @horo. Is my understanding correct? Is the idea shared among serviceworker guys?
Sorry I am @horo-t in github :)

>From the security perspective, we want to distinguish the partially consumed response.
I think:
 - The partially consumed response should be treated as the response which is created in the ServiceWorker, not the response from the server.
 - The URL of partially consumed response object should not be empty.

So my idea is:
 - response.body should be a method. (#606)
 - response.body() set bodyUsed flag, and returns Stream (ReadableStream?)
 - After response.body() was called, both cache.put(response) and FetchEvent.respondWith(rsponse) should fail.
 - If you want to read the header bytes of the response and returns to the page, you have to create a new response.

```javascript
self.addEventListener('fetch', function(event) {
  event.respondWith(
    fetch(event.request)
      .then(function(response){
          var stream = response.body();
          stream.readSomeBytes(); // This should be promise?
          return new Response(stream); // Tthis constructor is not speced yet.
        })
  });
```

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/452#issuecomment-70805311

Received on Wednesday, 21 January 2015 09:09:22 UTC