yutakahirano / fetch-with-streams

Fetch API integrated with Streams.
66 stars 8 forks source link

Request/Response constructor with a ReadableStream (not ReadableByteStream) #44

Closed tyoshino closed 7 years ago

tyoshino commented 9 years ago

The original question was raised by @yutakahirano

What we should do when the Request/Response constructor receive a ReadableStream (not ReadableByteStream)?

domenic commented 9 years ago

Probably the most straightforward thing to do is create some sort of wrapper. What type though? Here are three ideas:

In all cases the result will be not-great. The resulting ReadableByteStream will be "fake". Using its BYOB reader will be slow, not fast.


Another alternative would be to allow the body option and .body property to be ReadableStreams. If the author passes one in, we just allow that to be the .body. Later we can error during upload if the chunks are not binary data.

This means that sometimes you will get a Request/Response whose .body does not have a a .getByobReader(). That has pluses and minuses. It means you won't get "false advertising" from a fake RBS. But it also makes writing generic Request/Response processing code harder. But maybe that is good? We fail early if you're doing a stupid thing using your generic processing code?

There's a variant on this where we allow any object at all and just try to use its public API like we would a readable stream. But I think the appetite for that is low, understandably.


I don't feel too strongly here.

domenic commented 8 years ago

I think the original concern here is taken care of. However, we still have the potential for responses to have ReadableStreams that contain non-Uint8Array chunks. That means anything on the platform that consumes a Response might in theory have to deal with this.

Right now in practice that is a restricted problem. The only thing that consumes an author-generated Response is service worker's respondWith, which @yutakahirano is taking care of in https://github.com/slightlyoff/ServiceWorker/pull/934.

My inclination is to wait until we have a couple more examples of this pattern and then see if we want a more general solution.

annevk commented 7 years ago

This is superseded by https://github.com/whatwg/fetch/issues/450 I think.