ContentLength正在被剥离

2024-06-16 11:23:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是webpy0.34,python2.6.6。我也在用mimerender。我试图在我的http响应中包含内容长度,但是由于某些原因,头被删除了。我说removed是因为我可以很好地创建自定义头,并且我可以在客户机上看到这些头。但是,当我尝试设置内容长度时,头永远不会到达客户端。我试过在web.已创建对象(如图所示),我也尝试使用

web.header('Content-Length', len(data))

我做错了什么和/或不理解这些代码是如何工作的?在

^{pr2}$

Tags: 代码webhttp客户端内容data客户机len
1条回答
网友
1楼 · 发布于 2024-06-16 11:23:06

如果数据作为分块发送(Transfer-Encoding: chunked),则必须省略Content-Length头,as per RFC 2616

  1. [snip]

  2. If a Transfer-Encoding header field (section 14.41) is present and has any value other than "identity", then the transfer-length is defined by use of the "chunked" transfer-coding (section 3.6), unless the message is terminated by closing the connection.

  3. If a Content-Length header field (section 14.13) is present, its decimal value in OCTETs represents both the entity-length and the transfer-length. The Content-Length header field MUST NOT be sent if these two lengths are different (i.e., if a Transfer-Encoding header field is present). If a message is received with both a Transfer-Encoding header field and a Content-Length header field, the latter MUST be ignored.

相关问题 更多 >