Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
chunked request tests
#!/usr/bin/env python
import cherrypy
from pprint import pprint
class Root:
@cherrypy.expose
def index(self):
pprint(cherrypy.request.headers)
print(cherrypy.request.body.read())
return ''
if __name__ == '__main__':
cherrypy.quickstart(Root())
from http.client import HTTPConnection
def _compute_hash(data):
if data is None:
return {
'Trailer': 'foo',
}
c = HTTPConnection('localhost:8080')
c.on_chunked_data = _compute_hash
c.request('POST', '/', ('****' for _ in range(10)))
import uwsgi
# uwsgi --http :8080 --wsgi-file uwsgi_chunked.py --http-raw-body
def application(env, start_response):
data = uwsgi.chunked_read()
while data:
print(data)
data = uwsgi.chunked_read()
start_response('200 OK', [('Content-Type', 'text/html')])
return [b'Hello World']
import uwsgi
# uwsgi -s /tmp/uwsgi.sock --wsgi-file uwsgi_nginx_chunked.py --http-raw-body
def application(env, start_response):
print(env['wsgi.input'].read())
from pprint import pprint
pprint(env)
start_response('200 OK', [('Content-Type', 'text/html')])
return [b'Hello World']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment