The APIs offered by gevent.http.HTTPServer would seem to support streaming in both directions. The request object does not offer the request body as a simple string, but instead provides an .input_buffer attribute that is a Python iterable, while in the other direction the data for a response can be delivered as chunks with the three calls:

request.send_reply_start(200, 'OK')
request.send_reply_chunk(...)  # as many times as you wish
request.send_reply_end()

But I must have something mis-configured, because despite this wonderfully unbuffered API, my request handler is not getting called until the last chunk of request POST data has finally arrived, and in the other direction I am not seeing any headers arrive on my client socket until the server reaches .send_reply_end(). Is there some switch that I have to throw or some configuration setting that I have to manipulate in order to turn off buffering and see requests and send responses as they arrive, like gevent supports with raw sockets through its StreamServer?

My application needs to supports single-file uploads and downloads that may be bigger than RAM, which will require this buffering to be turned off.

Here are a simple server and client written with gevent that should show you this behavior:

# srv.py

import gevent.http

M100 = 100 * 1024 * 1024

def main():
    print 'Serving on 8088...'
    gevent.http.HTTPServer(('0.0.0.0', 8088), handle).serve_forever()

def handle(request):
    print 'Is request chunked?', request.chunked
    for item in request.input_buffer:
        print 'received body segment of length', len(item), 'bytes'
    request.add_output_header('Content-Type', 'application/octet-stream')
    request.send_reply_start(200, 'OK')
    for i in range(5):
        print 'sending chunk', i
        request.send_reply_chunk(M100 * 'x')
    request.send_reply_end()

i
Edit
Report