Implementations for receiving chunked requests (RFC2616) for Tornado. Two are available here.
The first in naive.py
is based on IOLoop.add_callback()
. We wrap callbacks with add_callback()
to avoid busting the stack limit in Python.
A more complex implementation is available in chunked_handler.py
. It's built on callback technique in this gist; for more, see this post: http://rctay.tuletech.com/2010/12/tornado-presenting-a-new-paradigm-for-IOStream-read-callbacks
While both work the same, it's recommended that you go with the latter for performance.
First, be sure to checkout submodule dependencies after cloning with
$ git submodule init
$ git submodule update
A simple standalone server is provided in main.py
. It binds to port 8000, and both handler implementations can be hit with requests to /chunked
and /chunked_naive
.
For example, you can test the naive implementation with
$ curl -v -H "Transfer-Encoding: chunked" --data-binary @some.file http://localhost:8000/chunked_naive
To add chunked functionality to your own handler, extend the handler implementation of your choice and override _on_chunks()
; it will be called when all the data is received with the chunked data as a file-like object (actually, a cStringIO
instance).