我正在使用 webpy 0.34,python 2.6.6。我也在使用 mimerender。我试图在我的 http 响应中包含内容长度,但由于某种原因,标头被删除。我说删除是因为我可以很好地创建自定义标头,并且我可以在客户端上看到这些标头。但是当我尝试设置内容长度时,标头永远不会到达客户端。我尝试将标头包含在 web.created 对象中(如图所示),并且我还尝试使用
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)})
I'm using webpy 0.34, python 2.6.6. I'm also using mimerender. I am trying to include the content-length in my http response, but for some reason the header is being removed. I say removed because I can create custom headers just fine, and I can see those headers on the client. But when I try to set content-length, the header never makes it to the client. I've tried including the header in the web.created object (as shown) and I've also tried using
web.header('Content-Length', len(data))
What am I doing wrong and/or not understanding about how this code works?
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
标头,根据 RFC 2616:If the data is sent as chunked (
Transfer-Encoding: chunked
), then theContent-Length
header must be omitted, as per RFC 2616: