Skip to content

Instantly share code, notes, and snippets.

@fafhrd91
Created April 25, 2014 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fafhrd91/11285108 to your computer and use it in GitHub Desktop.
Save fafhrd91/11285108 to your computer and use it in GitHub Desktop.
import io
from webob.request import Request
class Application:
def __init__(self, app):
self._app = app
def __call__(self, environ, start_response):
request = Request(environ)
# make 'wsgi.input' synchronous
if (request.method in ('POST', 'PUT') and
request.content_type in ('application/x-www-form-urlencoded',
'multipart/form-data')):
wsgiinput = io.BytesIO()
try:
while True:
wsgiinput.write((yield from environ['wsgi.input'].read()))
except aiohttp.EofStream:
pass
wsgiinput.seek(0)
environ['wsgi.input'] = wsgiinput
return self._app(environ, start_response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment