WSGI supports this, I believe. Here we'll echo whatever they send us:
def application(environ, start_response):
content_type = environ.get('CONTENT_TYPE', 'text/plain')
headers = [('Content-Type', content_type)]
if 'CONTENT_LENGTH' in environ:
headers.append(('Content-Length', environ['CONTENT_LENGTH']))
start_response('200 OK', headers)
input = environ.get('wsgi.input')
if input is None:
yield ''
return
while True:
datum = input.read(4096) # or so
if not datum:
return
yield datum
Web servers may elect to use each yield
as a Transfer-Encoding: chunked
chunk, though they are not required to.