fetch icon indicating copy to clipboard operation
fetch copied to clipboard

Allow request take AsyncIterable body?

Open ronag opened this issue 2 years ago • 9 comments

Would be possible/make sense to add AsyncIterable to the extract body algorithm? This would help with interopt with Node streams when implementing fetch in Node without violating the spec.

ronag avatar Aug 11 '21 14:08 ronag

Maybe.

However, we are going to add ReadableStream.from() to the Streams Standard which will at least make it trivial to construct a body from an AsyncIterable.

ricea avatar Aug 12 '21 05:08 ricea

Remember asking the exact same question a long time ago, but it got rejected by ReadableStream.from()

https://github.com/whatwg/fetch/issues/809

jimmywarting avatar Aug 28 '21 00:08 jimmywarting

@jimmywarting I don't think it got rejected, but you suggested to close it in favor of that API. Or am I missing something?

annevk avatar Aug 30 '21 07:08 annevk

yea, pretty much

jimmywarting avatar Aug 30 '21 07:08 jimmywarting

I really think this should be part of the standard. It makes Response so much easier to work with in Node.js, as we need to maintain backward compatibility with Node streams without incurring in the overhead of wrapping one stream type in another.

(Node.js ships this exactly for this reason).

mcollina avatar Mar 19 '24 19:03 mcollina

If this change is welcomed, I’m happy to champion this change and send a PR for it.

mcollina avatar Mar 19 '24 19:03 mcollina

In principle I'm supportive of this. The part that seems most tricky is how to make this work IDL-wise.

annevk avatar Mar 20 '24 08:03 annevk

The part that seems most tricky is how to make this work IDL-wise.

Some guidance on this would be fantastic.

mcollina avatar Mar 20 '24 13:03 mcollina

I have opened a PR to Web IDL with an attempt for how to make this work IDL wise: https://github.com/whatwg/webidl/pull/1397

lucacasonato avatar Mar 25 '24 14:03 lucacasonato