1. Jesper Nøhr
  2. django-fakesi

Commits

Jesper Nøhr  committed b9f3299

refactored nginx_ssi onto the request object under req.is_ssi

  • Participants
  • Parent commits 8826aa0
  • Branches master

Comments (0)

Files changed (2)

File fakesi/middleware.py

View file
 
 INCLUDE_TAG = re.compile(r'<!--#[\s.]+include[\s.]+virtual=["\'](?P<path>.+)["\'][\s.]+-->')
 
-def nginx_ssi(request):
-    return request.META.get('HTTP_NGINX_SSI', 'off') == 'on'
 
 class FakesiMiddleware(object):
+    def process_request(self, request):
+        def nginx_ssi(request):
+            return request.META.get('HTTP_NGINX_SSI', 'off') == 'on'
+
+        request.is_ssi = lambda *a, **kwa: nginx_ssi(request, *a, **kwa)
+
     def process_response(self, request, response):
-        if nginx_ssi(request):
+        if request.is_ssi():
             return response
         else:
             def ssi_include(match):

File fakesi/tests/templates/ssi.html

View file
 <p>I say, this is from SSI! I see you as '<b  id="user">{{ request.user }}</b>', on path '<b id="path">{{ request.path }}</b>'</p>
 <p>My variables are {{ request.GET }}</p>
-<p>You are from nginx: <b id="nginx">{% if request.META.HTTP_NGINX_SSI == "on" %}Yep!{% else %}Nope.{% endif %}</b></p>
+<p>You are from nginx: <b id="nginx">{% if request.is_ssi %}Yep!{% else %}Nope.{% endif %}</b></p>
 <p>Random number: <b id="random">{{ random }}</b></p>