Open Bug 1387483 Opened 5 years ago Updated 4 months ago

[Meta-Bug] Support ReadableStream as Request.body in fetch API

Categories

(Core :: DOM: Core & HTML, enhancement, P2)

enhancement

Tracking

()

Webcompat Priority revisit

People

(Reporter: bkelly, Unassigned)

References

(Depends on 1 open bug, Blocks 2 open bugs)

Details

(Keywords: dev-doc-needed)

Bug 1128959 is implementing support for ReadableStream as Response.body, but we are not implementing request bodies yet.  Request bodies are harder for a number of reasons:

1. HTTP/1.x effectively require fixed length upload bodies.
2. HTTP/2 can use chunked-encoding upload bodies, but we haven't implemented it yet.

Chrome has not yet shipped ReadableStream upload bodies either.
Depends on: streams
Priority: -- → P2
Is this the reason why the ReadableStream example in https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream doesn't work in Firefox even after changing the URL to a resource with properly defined CORS headers? It appears to work in Chrome and Edge.
(In reply to dtippett from comment #1)
> Is this the reason why the ReadableStream example in
> https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream doesn't work
> in Firefox even after changing the URL to a resource with properly defined
> CORS headers? It appears to work in Chrome and Edge.

I think that uses response.body.  This bug is about request body.  The code is probably not working in firefox because we have not exposed ReadableStream by default yet.  See bug 1389628.
Okay, thanks for the explanation.
Summary: Support ReadableStream as Request.body in fetch API → [Meta-Bug] Support ReadableStream as Request.body in fetch API
Depends on: 1469359
Flags: webcompat?
Whiteboard: [webcompat]
Blocks: 1479209
Duplicate of this bug: 1514883
Whiteboard: [webcompat] → [webcompat][webcompat-revisit]
Blocks: 1531373
No longer blocks: 1531373
Component: DOM → DOM: Core & HTML

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"

Migrating Webcompat whiteboard priorities to project flags. See bug 1547409.

Webcompat Priority: --- → ?

See bug 1547409. Migrating whiteboard priority tags to program flags.

Webcompat Priority: ? → revisit
Flags: webcompat?
Whiteboard: [webcompat][webcompat-revisit]

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.

You need to log in before you can comment on or make changes to this bug.