mirror of
https://github.com/c0de-archive/django-gallery.git
synced 2024-12-22 10:12:41 +00:00
51a117ca5f
CircleCI's free service only allows running 1 container at a time. This causes problems if I want to use a database. A workaround that I found seems to work by running the database server directly within the test container. This does increase test time however
28 lines
986 B
Python
28 lines
986 B
Python
import logging
|
|
from StringIO import StringIO
|
|
import zlib
|
|
class UnzipRequestMiddleware(object):
|
|
"""A middleware that unzips POSTed data.
|
|
|
|
For this middleware to kick in, the client must provide a value
|
|
for the ``Content-Encoding`` header. The only accepted value is
|
|
``gzip``. Any other value is ignored.
|
|
"""
|
|
|
|
def __init__(self, app):
|
|
self.app = app
|
|
|
|
def __call__(self, environ, start_response):
|
|
encoding = environ.get('HTTP_CONTENT_ENCODING')
|
|
if encoding == 'gzip':
|
|
data = environ['wsgi.input'].read()
|
|
try:
|
|
uncompressed = zlib.decompress(data, 31)
|
|
environ['wsgi.input'] = StringIO(uncompressed)
|
|
environ['CONTENT_LENGTH'] = len(uncompressed)
|
|
except zlib.error:
|
|
logging.warning(u"Could not decompress request data.", exc_info=True)
|
|
environ['wsgi.input'] = StringIO(data)
|
|
return self.app(environ, start_response)
|
|
|