为什么 Comet 需要分块编码响应?

发布于 2024-07-26 03:08:56 字数 177 浏览 3 评论 0原文

我读了一些关于彗星技术的文章。 他们都提到长寿命的 HTTP 响应应该是 Transfer-Encoding: chunked 。 我想知道为什么它应该被分块编码。 如果响应不是分块编码的,客户端 JavaScript 仍然可以读取并解析响应的文本,对吗?

Comet 响应应该进行分块编码有什么特殊原因吗?

I read some articles about Comet tech. All of them mentioned that the long-life HTTP response should be Transfer-Encoding: chunked . I'm wondering why it should be chunked-encoded. If the response is not chunked-encoded, the client javascript can still read and parse the responded text, right?

Is there any special reason that Comet response should be chunked-encoded?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2024-08-02 03:08:56

当响应完成之前未知响应长度时,使用分块编码响应。 空块表示响应的结束。 这是通知客户端响应结束的唯一方法。

所有这些都非常适合彗星。 收到请求后,您发送第一个块。 您还可以在等待操作完成时发送额外的“心跳”块。 空块将通知客户端响应已完成。

Chunked-encoded response is used when the length of the response is not known until the response is completed. An empty chunk indicates the end of the response. This is the only way the client can be notified for the end of response.

All this fit nicely with Comet. You send the first chunk when the request is received. You may also send additional "heartbeat" chunks while waiting for an action to complete. An empty chunk will notify the client that the response is completed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文