Re: [whatwg/fetch] Fail request when its streaming body is used in ServiceWorker (#1144)

@yutakahirano commented on this pull request.



> @@ -3834,9 +3834,32 @@ optional <i>CORS-preflight flag</i>, run these steps:
   <p>If <var>request</var>'s <a>service-workers mode</a> is "<code>all</code>", then:
 
   <ol>
+   <li><p>Assert: <var>request</var> 's <a for=request>body</a> is either null or a
+   <a for=/>body</a>.
+
+   <li>
+    <p>Let <var>savedBody</var> be a copy of <var>request</var>'s <a for=request>body</a>.

Let's assume `req` has a body made from a ReadableStream, and it's intercepted in the service worker.

```
self.addEventListener('fetch', (e) => {
  const req = e.request;
  const clonedBody = req.clone();

  ...

  return null;
});
```

The above handler calls `clone()` and returns null. If we support this use case,

 1. [Tee](https://streams.spec.whatwg.org/#rs-tee) runs in the service worker realm,
 2. One of the streams made by [Tee](https://streams.spec.whatwg.org/#rs-tee) is transferred to the network process.

Hence shutting down the service worker shuts down the teeing logic, which breaks the transferred stream in the network process.
 


-- 
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/pull/1144#discussion_r572725257

Received on Tuesday, 9 February 2021 09:31:38 UTC