gpt4 book ai didi

python - 内容长度被剥离

转载 作者:太空宇宙 更新时间:2023-11-04 01:40:27 25 4
gpt4 key购买 nike

我使用的是 webpy 0.34、python 2.6.6。我也在使用 mimerender。我试图在我的 http 响应中包含内容长度,但由于某种原因,标题被删除了。我说删除是因为我可以很好地创建自定义 header ,而且我可以在客户端上看到这些 header 。但是当我尝试设置内容长度时, header 永远不会到达客户端。我试过在 web.created 对象中包含 header (如图所示),我也试过使用

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

我做错了什么和/或不理解这段代码的工作原理?

render_json = lambda **args: json.JSONEncoder().encode(args)

class MyHandler:
@mimerender(
default = 'json',
json = render_json,
)
def POST(self):
data = "abcd"
raise web.created(data, headers={'Content-Length': len(data)})

最佳答案

如果数据以分块形式发送(Transfer-Encoding: chunked),则必须省略Content-Length header ,as per RFC 2616 :

  1. [snip]
  1. If a Transfer-Encoding header field (section 14.41) is present andhas any value other than "identity", then the transfer-length isdefined by use of the "chunked" transfer-coding (section 3.6),unless the message is terminated by closing the connection.
  1. If a Content-Length header field (section 14.13) is present, itsdecimal value in OCTETs represents both the entity-length and thetransfer-length. The Content-Length header field MUST NOT be sentif these two lengths are different (i.e., if a Transfer-Encodingheader field is present). If a message is received with both aTransfer-Encoding header field and a Content-Length header field,the latter MUST be ignored.

关于python - 内容长度被剥离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5553151/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com