(Chunked)HTTP二进制消息体和CRLF [英] (Chunked) HTTP binary message body and CRLFs

查看:105
本文介绍了(Chunked)HTTP二进制消息体和CRLF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到以下问题的明确答案(谷歌搜索并阅读HTTP / 1.1规范):

I cannot seem to get a definitive answer on the following question (Googling mostly and reading HTTP/1.1 specs):

当使用'chunked'传输编码时,为什么服务器需要以字节为单位写出块大小,并使后续块数据以CRLF结束。这不会使发送二进制数据CRLF-unclean并且方法有点多余吗?如果数据在某处有一个0x0A后跟0x0D(即这些实际上是数据的一部分)怎么办?是否期望客户端遵守在数据中遇到的第一个CRLF上的块头或阻塞处明确提供的块大小?到目前为止,我的理解是简单地获取服务器提供的块大小,继续下一行,然后从以下数据中读取这个字节数(CRLF或内部没有CRLF),然后跳过跟随数据的CRLF并重复这个程序,直到没有更多的块...我是对的吗?那么每个数据库之后的CRLF有什么意义呢?可读性?

When 'chunked' transfer encoding is used, why does the server need to write out BOTH the chunk size in bytes and have the subsequent chunk data end with CRLF. Doesn't this make sending binary data "CRLF-unclean" and the method a bit redundant? What if the data has a 0x0A followed by 0x0D in it somewhere (i.e. these are actually part of the data)? Is the client expected to adhere to the chunk size explicitly provided at the head of the chunk or choke on the first CRLF it encounters in the data? My understanding so far is to simply take the chunk size provided by the server, proceed to the next line, then read exactly this amount of bytes from within the following data(CRLF or no CRLF inside), then skip that CRLF that follows the data and repeat the procedure until no more chunks... Am I right? What is the point of the CRLF after each datachunk then? Readability?

推荐答案

分块消费者不会扫描消息正文以获取CRLF对。它首先读取指定的字节数,然后再读取两个字节以确认它们是CR和LF。如果不是,则邮件正文格式不正确,或者指定的大小不正确或者数据已损坏。

A chunked consumer does not scan the message body for a CRLF pair. It first reads the specified number of bytes, and then reads two more bytes to confirm that they are CR and LF. If they're not, the message body is ill-formed, and either the size was specified improperly or the data was otherwise corrupted.

尾随CRLF是一条带 - 和吊带保证(根据 RFC 2616第3.6.1节 Chunked Transfer Coding ),但它也用于维护字段从行开头开始的一致规则。

The trailing CRLF is a belt-and-suspenders assurance (per RFC 2616 section 3.6.1, Chunked Transfer Coding), but it also serves to maintain the consistent rule that fields start at the beginning of the line.

这篇关于(Chunked)HTTP二进制消息体和CRLF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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