Open Bug 1544313 Opened 5 years ago Updated 2 years ago

fetch/response/body stream buffers data when Content-Type is not set

Categories

(Core :: DOM: Networking, defect, P3)

66 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: ondras, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [necko-triaged])

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0

Steps to reproduce:

Streaming the fetch's response body:

let response = await fetch("/");
let reader = response.body.getReader();
while (1) {
  let { ... } = await reader.read();
  ...
}

Actual results:

The read() call waits for the whole response, even for chunked Content-Transfer-Encoding. This happens only when there is no Content-Type response header.

Expected results:

The read() should resolve a promise for every chunk received. This happens when a Content-Type header is present.

Component: Untriaged → DOM: Networking
Product: Firefox → Core
Priority: -- → P2
Whiteboard: [necko-triaged]

I can still reproduce this bug. The buffered amount at the start of the stream seems to be around 512 bytes. After that the entire first 512 bytes are emitted in a single chunk, and after that everything works as expected. Would the addition of a WPT test here be helpful?

To elaborate, for me the promise returned from fetch does not even resolve until the first 512 bytes of data have been sent over the stream.

A WPT test would be great!

I suspect you are trying to use this for streaming and having to stream 512 bytes first is rather problematic?

Added a test in https://github.com/web-platform-tests/wpt/pull/29698.

I suspect you are trying to use this for streaming and having to stream 512 bytes first is rather problematic?

It's mainly just really unexpected that in Chrome the streaming works right away, but in FF it hangs until the first 512 bytes have been sent. Took me a few hours to debug this and narrow it down to a small reproduction, and wouldn't want other people to run into the same issue. Once I figured out what the issue was I just added a content-type header and everything worked as expected.

Blocks: fetch
Priority: P2 → P3

This is probably caused by the content type sniffer.
We should probably bypass it for fetch requests.

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.