Content-Length Loses

I am using webpy 0.34, python 2.6.6. I also use mimerender. I am trying to include the length of the content in my HTTP response, but for some reason the header is being deleted. I say that delete, because I can create custom headers just fine, and I can see these headers on the client. But when I try to set the length of the content, the header never makes it to the client. I tried to include the header in the web.created object (as shown), and I also tried using

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

What am I doing wrong and / or do not understand 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)}) 
+2
python web.py web-services
source share
1 answer

If data is sent as chunked ( Transfer-Encoding: chunked ), then the Content-Length header should be omitted, in accordance with RFC 2616 :

  • [incision]

  • If the Transfer-Encoding header field (section 14.41) is present and has any value other than "identity", then the transmission length is determined using the "packet" transmission encoding (section 3.6) if the message is not completed by closing the connection.

  • If the Content-Length header field (section 14.13) is present, its decimal value in OCTET represents both the length of the object and the Transfer length. The Content-Length header field SHOULD NOT be sent if the two lengths are different (that is, if the transfer-encoding header field). If the message is received as with the Transfer-Encoding header field and the Content-Length header field, the latter MUST be ignored.

+3
source share

All Articles