Best way to avoid chunked encoding in HTTP Resource response?

Tom Sheffler <[email protected]>
Newsgroups gmane.comp.python.twisted.web
Message-ID <CAMBtMcsVuqauDtgxTSjkhmaM-adByLxxYGEyVwj4aG518=NGnA@mail.gmail.com>
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

_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.