Re: [ServiceWorker] Can we change the body attribute of Request/Response to a method? (#606)

I discussed with @tyoshino, and I changed my mind. I think .body should be a method.

In my understanding, there are five players.
[1] The network server.
[2] The browser process who handles network requests and cache APIs.
[3] ServiceWorker in JavaScript world.
[4] The renderer process for page.
[5] Cache data storage.

1. When the ServiceWorker calls fetch() ant gets the Response object, Response has HTTP headers information and the pointer to the data flow ([1] -> [2]).
2. When the ServiceWorker calls FetchEvent.respondWith(response), the ServiceWorker asks the browser to forward the flow ([1]->[2]) to the page [4].
3. When the ServiceWorker calls cache.put(response), the ServiceWorker asks the browser to forward the flow ([1]->[2]) to the cache [5].
4. When the ServiceWorker wants to read the body of the response, the ServiceWorker needs to ask the browser to forward the flow ([1]->[2]) to the ServiceWorker [3]. (I think the flow ([2]->[3]) is what the ReadableStream represents.) So getting the ReadableStream is an action. So .body() should be a method.
5. If the ServiceWorker reads some amount of the body from the ReadableStream, and call FetchEvent.respondWith(response), the remaining body data will go through this flow ([1]->[2]->[3]->[2]->[4])
6. If the ServiceWorker reads some amount of the body from the ReadableStream, and call cache.put(response), the remaining body data will go through this flow ([1]->[2]->[3]->[2]->[5])

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

Received on Thursday, 22 January 2015 08:55:45 UTC