It would be nice to have a synchronous feature detect for streaming requests. This currently works with the Chrome implementation:
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?
It would be nice to have a synchronous feature detect for streaming requests. This currently works with the Chrome implementation:
This tests that:
duplexis implemented as part ofRequestInitbodycan be aReadableStream. Otherwise, it's converted to a string and gets atext/plaincontent 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 implementduplexso 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?