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

> 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.

I agree we need to spec types.  Can we do something in webidl like ReadableStream<Uint8Array> with defined semantics if it hits a different chunk type?

> At first I thought this would be related to structured cloning of readable streams (whatwg/streams#276 and whatwg/streams#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 don't understand this one.  Just because the outer ReadableStream is locked does not prevent the inner source from continuing to provide data, right?

If we're using a Transform like a pipe, then the readable and writable sides really need to be individually lockable.  Locking the reader side should not block other code from locking/using the writable side.  This should be achievable via the inner source object.

> Otherwise, transfer it across realms/event loops, and enqueue it in the page-side ReadableStream.

I guess we can do this, but its likely just going to be a spec thing.  I doubt we will ever represent actual browser images, stylesheets, etc as ReadableStreams.  We're just going to consume them in c++.  The only place it will actually happen this way is in an outer fetch() call that returns a Response.body.

> We (Chrome) serialize the buffers to a C++ byte array and create Uint8Array objects from the byte array in the page. That means buffer's boundary is not preserved (i.e., buffers may be merged / split). As an implementer I would like the spec to allow us doing it.

Yea, I think its totally up to the browser what they do with the buffers.  I don't want the spec to require a one-to-one buffer correspondence between a service worker provided Response.body and the outer fetch()'s Response.body that triggered the service worker interception.

---
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#issuecomment-231379485

Received on Friday, 8 July 2016 14:48:14 UTC