HTTP多部分“内容长度”如何?标头值计算? [英] How is an HTTP multipart "Content-length" header value calculated?
问题描述
我读过对如何计算多部分HTTP请求内容长度?这一问题的冲突和有些含糊不清的回复。我特别想知道:
I've read conflicting and somewhat ambiguous replies to the question "How is a multipart HTTP request content length calculated?". Specifically I wonder:
- 计算Content-length标题的精确内容范围是什么?
- CRLF(\\ n)八位字节序列是否计为一个或两个八位字节?
可以有人提供了一个明确的例子来回答这些问题吗?
Can someone provide a clear example to answer these questions?
推荐答案
你如何计算 Content-Length
不依赖于有效载荷的状态代码或媒体类型;它是线上的字节数。因此,编写多部分响应,计算字节数(并且 CRLF
计为2),并将其用于 Content-Length
。
How you calculate Content-Length
doesn't depend on the status code or media type of the payload; it's the number of bytes on the wire. So, compose your multipart response, count the bytes (and CRLF
counts as two), and use that for Content-Length
.
请参阅: http://httpwg.org/specs/rfc7230.html#message.body.length
这篇关于HTTP多部分“内容长度”如何?标头值计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!