[Twisted-web] Best way to avoid chunked encoding in HTTP Resource response?
Tom Sheffler
tom.sheffler at gmail.com
Thu Apr 19 11:37:50 EDT 2012
A straightforward use of a series of request.write()s with a
request.finish() in the render_GET() method of a resource defaults to
chunked encoding. I can avoid the chunked encoding by computing the entire
response first using a StringIO (as shown below) and explicitly putting the
"Content-Length" header in myself.
Is this the best (or recommended) way to create such a response?
Thx - Tom
=============
class myresource(Resource):
def render_GET(self, response):
output = StringIO.StringIO()
output.write("...")
output.write("...")
...
data = output.getvalue()
output.close()
# Write the response data. "content-length" suppresses chunked coding
request.setHeader('content-length', len(data))
request.write(data)
request.finish()
return True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20120419/02dfcc22/attachment.htm
More information about the Twisted-web
mailing list