分块传输编码 - 浏览器行为 [英] Chunked transfer encoding - browser behavior

查看:23
本文介绍了分块传输编码 - 浏览器行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以分块模式发送数据.所有标题都正确设置,数据也相应地编码.浏览器将我的响应识别为分块响应,接受标头并开始接收数据.

I'm trying to send data in chunked mode. All headers are set properly and data is encoded accordingly. Browsers recognize my response as a chunked one, accepting headers and start receiving data.

我原以为浏览器会在每个接收到的块上更新页面,而是等到所有块都接收到然后将它们全部显示出来.这是预期的行为吗?

I was expecting the browser would update the page on each received chunk, instead it waits until all chunks are received then displays them all. Is this the expected behavior?

我期待看到每个块在收到后立即显示.使用 curl 时,每个块在收到后立即显示.为什么 GUI 浏览器不会发生同样的情况?他们是否使用某种缓冲/缓存?

I was expecting to see each chunk displayed right after it was received. When using curl, each chunk is shown right after it is received. Why does the same not happen with GUI browsers? Are they using some sort of buffering/cache?

我将 Cache-Control 标头设置为 no-cache,所以不确定它是否与缓存有关.

I set the Cache-Control header to no-cache, so not sure it is about cache.

推荐答案

afaik 浏览器需要一些有效负载才能在收到时开始渲染块.
Curl当然是个例外.

afaik browsers needs some payload to start render chunks as they received.
Curl is of course an exception.

尝试在第一个数据块之前发送大约 1KB 的任意数据.

Try to send about 1KB of arbitrary data before your first chunk.

如果你做的一切都正确,浏览器应该按照接收到的方式呈现块.

If you are doing everything correctly, browsers should render chunks as they received.

这篇关于分块传输编码 - 浏览器行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆