def __call__(self, environ, start_response):
if environ.get('HTTP_CONTENT_ENCODING', '') == 'gzip':
try:
environ['wsgi.input'].tell()
wsgi_input = environ['wsgi.input']
except (AttributeError, IOError, NotImplementedError):
# The gzip implementation in the standard library of Python 2.x
# requires working '.seek()' and '.tell()' methods on the input
# stream. Read the data into a temporary file to work around
# this limitation.
wsgi_input = tempfile.SpooledTemporaryFile(16 * 1024 * 1024)
shutil.copyfileobj(environ['wsgi.input'], wsgi_input)
wsgi_input.seek(0)
environ['wsgi.input'] = gzip.GzipFile(filename=None, fileobj=wsgi_input, mode='r')
del environ['HTTP_CONTENT_ENCODING']
if 'CONTENT_LENGTH' in environ:
del environ['CONTENT_LENGTH']
return self.app(environ, start_response)
评论列表
文章目录