Skip to content

Instantly share code, notes, and snippets.

@demianbrecht
Created March 7, 2015 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demianbrecht/3fd60994eceeb3da8f13 to your computer and use it in GitHub Desktop.
Save demianbrecht/3fd60994eceeb3da8f13 to your computer and use it in GitHub Desktop.
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