Commit 101990d2 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Use get_input_stream from werkzeug for reading the request body

parent 36892889
Pipeline #20448 passed with stages
in 3 minutes and 8 seconds
......@@ -3,6 +3,7 @@
import gzip
import sentry_sdk
from werkzeug.wsgi import get_input_stream
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
from cStringIO import StringIO
from werkzeug.exceptions import HTTPException
......@@ -85,10 +86,9 @@ class GzipRequestMiddleware(object):
self.app = app
def __call__(self, environ, start_response):
# XXX can we do this without loading everything into memory?
content_encoding = environ.get('HTTP_CONTENT_ENCODING', '').lower().strip()
if content_encoding == 'gzip' and 'wsgi.input' in environ and 'CONTENT_LENGTH' in environ:
compressed_body = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH']))
if content_encoding == 'gzip':
compressed_body = get_input_stream(environ).read()
body = gzip.GzipFile(fileobj=StringIO(compressed_body)).read()
environ['wsgi.input'] = StringIO(body)
environ['CONTENT_LENGTH'] = str(len(body))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment