[whatwg/fetch] Feature detecting streaming requests (Issue #1470)

It would be nice to have a synchronous feature detect for streaming requests. This currently works with the Chrome implementation:

```js
const supportsRequestStreams = (() => {
  let duplexAccessed = false;

  const hasContentType = new Request('', {
    body: new ReadableStream(),
    method: 'POST',
    get duplex() {
      duplexAccessed = true;
      return 'half';
    },
  }).headers.has('Content-Type');

  return duplexAccessed && !hasContentType;
})();
```

This tests that:

- `duplex` is implemented as part of `RequestInit`
- `body` can be a `ReadableStream`. Otherwise, it's converted to a string and gets a `text/plain` content type.

However, it's possible that an implementation could support these two things, but reject when that request is passed to `fetch()` because it doesn't support request streams. In fact, Safari already behaves like this, but it doesn't implement `duplex` so the test still works.

Is it reasonable to expect the above feature detect to mean "fetch supports streaming requests"? Should this be enforced with spec text and/or a wpt?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1470
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/issues/1470@github.com>

Received on Tuesday, 12 July 2022 12:00:04 UTC