Skip to content

Feature detecting streaming requests #1470

Description

@jakearchibald

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions