[Meta-Bug] Support ReadableStream as Request.body in fetch API
Categories
(Core :: DOM: Core & HTML, enhancement, P2)
Tracking
()
People
(Reporter: bkelly, Unassigned)
References
(Depends on 1 open bug, Blocks 2 open bugs)
Details
(Keywords: dev-doc-needed)
Updated•7 years ago
|
Updated•7 years ago
|
Reporter | ||
Comment 2•7 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Comment 5•6 years ago
|
||
At the moment passing ReadableStream
as body to a fetch
or a Request
constructor produces request that has body that is just body.toStrin()
:
const encoder = new TextEncoder()
const request = new Request('about:blank', {
method: "PUT",
body: new ReadableStream({
pull(c) {
c.enqueue(encoder.encode("hello"))
c.close()
}
})
})
await request.text() // -> "[object ReadableStream]"
I think we should at least error until support for body has landed, especially given that Response
accepts ReadableStream
just fine.
const encoder = new TextEncoder()
const response = new Response(new ReadableStream({
pull(c) {
c.enqueue(encoder.encode("hello"))
c.close()
}
}))
await response.text() // -> "hello"
Comment 6•6 years ago
|
||
Migrating Webcompat whiteboard priorities to project flags. See bug 1547409.
Comment 7•6 years ago
|
||
See bug 1547409. Migrating whiteboard priority tags to program flags.
Updated•5 years ago
|
Are there any plans to implement this in FF? whatwg seems to be considering removing it from the standard as no browser is implementing it.
I think this would be a huge loss for the web, as even things like firefox send need to resort to hacks like uploading large files via websockets.
Hi,
Chrome 85 includes this feature.
Here are links.
- Chrome Platform Status: fetch() upload streaming
- web.dev: Streaming requests with the fetch API
- Chromium Blog:
Chrome 85: Upload Streaming, Human Interface Devices, Custom Properties with Inheritance and More
It seems Chrome people now think this may not be so useful.
Comment 11•2 years ago
|
||
I read through the (now closed) issue on github and it seems that they'll keep the feature, as many people found it very useful (me included). I did give it a try in Chrome 105 and found it to be working pretty well - with the limitations that the web server needs to run on HTTP2, HTTPS must be used, and only the "half-duplex" mode is supported. But even so, it's very useful and I would really love to see this in Firefox as well.
As many people can't imagine why this would be worth the effort, let me give you an example: I am currently working on a end-to-end encryption of files, completely done in the browser. You can imagine why loading the entire file into memory, encrypting it there and then sending it to a server in one piece isn't feasible - for anything but small image files, that is. I managed to come up with a relatively simple proof-of-concept that encrypts any file on the client side and sends this with a single fetch (POST) to a Kestrel server - and later downloads and decrypts the same file again. It works perfectly in Chrome (both on desktop and smartphone) but not on Firefox, which is a shame. As the whole idea behind this project is privacy, I wouldn't want to depend on Chrome for using it.
tl;dr: Please bring this to Firefox - even with limitations (like half-duplex HTTPS 2 only), it's pretty useful.
Updated•2 years ago
|
Updated•2 years ago
|
Description
•