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

When the ServiceWorker responds to the FetchEvent with a cached response, ServiceWorker don't need to know the body content of the response object. In such case, we don't want to send the content to the ServiceWorker. For optimization, we want to send the content only when the ServiceWorker script accesses to the content.
```javascript
self.addEventListener('fetch', function(event) {
  event.respondWith(
    cache.match('http://example.com/file/')
      .then(function(response) {
          return response;
        }));
  });
```
Response.body provides a way to access to the content. So we want to send the content when Response.body is accessed. This means Response.body is a side-effecting attribute.

I think side-effecting attributes are not good. For example, ```console.log(response);``` may cause unexpected behaviour. So I want Response.body to be a method.

Furthermore, if Response.body is a method, comparing two response objects in tests become easier. We are currently using [custom assert_object_equals()](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/override_assert_object_equals.js) in tests not to access to Response.body attribute while comparing two response objects.

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

Received on Tuesday, 20 January 2015 14:36:57 UTC