2013-03-06 23:33:51 +00:00
|
|
|
from django.http import HttpResponse, StreamingHttpResponse
|
2015-12-30 15:51:16 +00:00
|
|
|
from django.urls import reverse
|
2015-11-07 15:12:37 +00:00
|
|
|
from django.utils.deprecation import MiddlewareMixin
|
2013-03-06 23:33:51 +00:00
|
|
|
|
2011-10-13 21:34:56 +00:00
|
|
|
from . import urlconf_inner
|
|
|
|
|
2009-11-16 01:58:00 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
class ChangeURLconfMiddleware(MiddlewareMixin):
|
2009-11-16 01:58:00 +00:00
|
|
|
def process_request(self, request):
|
|
|
|
request.urlconf = urlconf_inner.__name__
|
2010-03-26 15:08:24 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
class NullChangeURLconfMiddleware(MiddlewareMixin):
|
2010-03-26 15:08:24 +00:00
|
|
|
def process_request(self, request):
|
|
|
|
request.urlconf = None
|
2013-03-06 23:33:51 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
class ReverseInnerInResponseMiddleware(MiddlewareMixin):
|
2013-03-06 23:33:51 +00:00
|
|
|
def process_response(self, *args, **kwargs):
|
|
|
|
return HttpResponse(reverse("inner"))
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
class ReverseOuterInResponseMiddleware(MiddlewareMixin):
|
2013-03-06 23:33:51 +00:00
|
|
|
def process_response(self, *args, **kwargs):
|
|
|
|
return HttpResponse(reverse("outer"))
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
class ReverseInnerInStreaming(MiddlewareMixin):
|
2013-03-06 23:33:51 +00:00
|
|
|
def process_view(self, *args, **kwargs):
|
|
|
|
def stream():
|
|
|
|
yield reverse("inner")
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2013-03-06 23:33:51 +00:00
|
|
|
return StreamingHttpResponse(stream())
|
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2015-11-07 15:12:37 +00:00
|
|
|
class ReverseOuterInStreaming(MiddlewareMixin):
|
2013-03-06 23:33:51 +00:00
|
|
|
def process_view(self, *args, **kwargs):
|
|
|
|
def stream():
|
|
|
|
yield reverse("outer")
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2013-03-06 23:33:51 +00:00
|
|
|
return StreamingHttpResponse(stream())
|