生物特征 高性能服务 智能交互分享 http://blog.sciencenet.cn/u/bluewind23 带着鲜刺的玫瑰刺得血如雨下一如既往前行!

博文

about HTTP chunked+gzip

已有 9598 次阅读 2013-6-25 15:03 |个人分类:高性能服务|系统分类:科研笔记| http, gzip, chunked

   
  • Chunked transfer encoding allows a server to maintain an HTTP persistent connection for dynamically generated content. In this case the HTTP Content-Length header cannot be used to delimit the content and the next HTTP request/response, as the content size is as yet unknown. Chunked encoding has the benefit that it is not necessary to generate the full content before writing the header, as it allows streaming of content as chunks and explicitly signaling the end of the content, making the connection available for the next HTTP request/response.

  • Chunked encoding allows the sender to send additional header fields after the message body. This is important in cases where values of a field cannot be known until the content has been produced such as when the content of the message must be digitally signed. Without chunked encoding, the sender would have to buffer the content until it was complete in order to calculate a field value and send it before the content.

  • HTTP servers sometimes use compression (gzip) or deflate methods to optimize transmission. How both chunked and gzip encoding interact is dictated by the two-staged encoding of HTTP: first the content stream is encoded as (Content-Encoding: gzip), after which the resulting byte stream is encoded for transfer using another encoder (Transfer-Encoding: chunked). This means that in case both compression and chunked encoding are enabled, the chunk encoding itself is not compressed, and the data in each chunk should not be compressed individually. The remote endpoint can decode the incoming stream by first decoding it with the Transfer-Encoding, followed by the specified Content-Encoding.

      above from: http://en.wikipedia.org/wiki/Chunked_transfer_encoding

    译:

  1. HTTP分块传输编码允许服务器为动态生成的内容维持HTTP持久链接。通常,持久链接需要服务器在开始发送消息体前发送Content-Length消息头字段,但是对于动态生成的内容来说,在内容创建完之前是不可知的。 分块编码的好处,没有必要在获取完整的内容之前写头字段,它允许内容流分块(chunk),并显式标记内容的末尾,使连接可用于下一个HTTP请求/响应。

  2. 分块传输编码允许服务器在最后发送消息头字段。对于那些头字段值在内容被生成之前无法知道的情形非常重要,例如消息的内容要使用散列进行签名,散列的结果通过HTTP消息头字段进行传输。没有分块传输编码时,服务器必须缓冲内容直到完成后计算头字段的值并在发送内容前发送这些头字段的值。

  3. HTTP服务器有时使用压缩 (gzip或deflate)以缩短传输花费的时间。分块传输编码可以用来分隔压缩对象的多个部分。在这种情况下,块不是分别压缩的,而是整个负载进行压缩,压缩的输出使用本文描述的方案进行分块传输。在压缩的情形中,分块编码有利于一边进行压缩一边发送数据,而不是先完成压缩过程以得知压缩后数据的大小。

  注:如果采用chunked+gzip方式,并且每个chunk都是一个gzip压缩包的方式,浏览器不支持


 



https://blog.sciencenet.cn/blog-297739-702590.html

上一篇:简单的去除光照影响:归一化RGB色彩模型
下一篇:三次握手与四次挥手
收藏 IP: 59.42.225.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-1 19:02

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部