HTTP chunked
chunk是http协议新增的一种分块传输编码格式,用于服务传输那些非静态页面(大小固定)。此类页面旺旺需要动态响应,即一遍产生数据,一遍发送给客户端,服务器并不知道页面内容的大小。
使用格式
- 消息头部:Transfer-Encoding: chunked
- 若干chunk:第一部分是该chunk的长度,第二部分就是指定长度的内容,每个部分用CRLF隔开,最后以一个长度为0的chunk结束,即"0\r\n\r\n"。
- 格式:[chunk size][\r\n][chunk data][\r\n][chunk size][\r\n][chunk data][\r\n][chunk size = 0][\r\n][\r\n]
- chunk size是以十六进制的ASCII码表示,即对于31 34 对应的ASCII值为49 52,即1和4,对应十进制为20
举例:
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
25 => (37个字符,包含有"\r\n")
This is the data in the first chunk
1C => (28个字符,包含有"\r\n")
and this is the second one
3
con
8
sequence
0 => ("0\r\n\r\n")
以上即为:
This is the data in the first chunk
and this is the second one
consequence
参考:[添加链接描述]