mirror of
https://github.com/kennethreitz-archive/django-piston-xauth.git
synced 2026-06-16 21:40:58 +00:00
21 lines
833 B
Python
21 lines
833 B
Python
from django.middleware.http import ConditionalGetMiddleware
|
|
from django.middleware.common import CommonMiddleware
|
|
|
|
def compat_middleware_factory(klass):
|
|
"""
|
|
Class wrapper that only executes `process_response`
|
|
if `streaming` is not set on the `HttpResponse` object.
|
|
Django has a bad habbit of looking at the content,
|
|
which will prematurely exhaust the data source if we're
|
|
using generators or buffers.
|
|
"""
|
|
class compatwrapper(klass):
|
|
def process_response(self, req, resp):
|
|
if not hasattr(resp, 'streaming'):
|
|
return klass.process_response(self, req, resp)
|
|
return resp
|
|
return compatwrapper
|
|
|
|
ConditionalMiddlewareCompatProxy = compat_middleware_factory(ConditionalGetMiddleware)
|
|
CommonMiddlewareCompatProxy = compat_middleware_factory(CommonMiddleware)
|