1 from django.middleware.http import ConditionalGetMiddleware
2 from django.middleware.common import CommonMiddleware
4 def compat_middleware_factory(klass):
6 Class wrapper that only executes `process_response`
7 if `streaming` is not set on the `HttpResponse` object.
8 Django has a bad habbit of looking at the content,
9 which will prematurely exhaust the data source if we're
10 using generators or buffers.
12 class compatwrapper(klass):
13 def process_response(self, req, resp):
14 if not hasattr(resp, 'streaming'):
15 return klass.process_response(self, req, resp)
19 ConditionalMiddlewareCompatProxy = compat_middleware_factory(ConditionalGetMiddleware)
20 CommonMiddlewareCompatProxy = compat_middleware_factory(CommonMiddleware)