[whatwg/fetch] How response bodies get from a service worker to the main page is not very clear (#330)

Right now the spec says that the internal response has a ReadableStream object. Since the internal response is shared between the service worker and the page, the ReadableStream is implicitly shared.

This is not very good. For example it implies sharing arbitrary JavaScript objects, since you can enqueue arbitrary JavaScript objects in the readable stream. Right now Chrome ignores all objects except Uint8Arrays. It should instead error in some way, but exactly how is not clear, since there is no spec.

At first I thought this would be related to structured cloning of readable streams (https://github.com/whatwg/streams/issues/276 and https://github.com/whatwg/streams/issues/244) but that might not be true. Our plan for structured cloning was to lock the stream. But that will not work in this case, as we want the service worker code to be able to enqueue at the same time the main thread code is reading.

I guess what we need to do is specify how each `Response` object has a `ReadableStream` object. Then respondWith() roughly does the following:

- Create a new page-side `ReadableStream`
- Read chunks from the service worker's `Response`'s `ReadableStream`. For each chunk:
  - If it is not a Uint8Array, error the page-side `ReadableStream`
  - Otherwise, transfer it across realms/event loops, and enqueue it in the page-side `ReadableStream`.

Apologies if we already have some of this and I missed it.

---
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/330

Received on Thursday, 7 July 2016 17:15:20 UTC