Created
April 25, 2014 10:40
-
-
Save fafhrd91/11285108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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