]> git.0d.be Git - panikweb.git/commitdiff
performance: strip piwik cookies, so requests are cached for everybody
authorFrédéric Péters <fpeters@0d.be>
Thu, 12 Sep 2013 07:58:56 +0000 (09:58 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 12 Sep 2013 07:58:56 +0000 (09:58 +0200)
panikweb/middleware.py [new file with mode: 0644]
panikweb/settings.py

diff --git a/panikweb/middleware.py b/panikweb/middleware.py
new file mode 100644 (file)
index 0000000..36a915c
--- /dev/null
@@ -0,0 +1,11 @@
+import re
+
+class StripPiwikCookieMiddleware(object):
+    # idea from http://djangosnippets.org/snippets/1772/
+    strip_re = re.compile(r'(_pk_[a-z0-9\.]+=.+?(?:; |$))')
+    def process_request(self, request):
+        try:
+            cookie = self.strip_re.sub('', request.META['HTTP_COOKIE'])
+            request.META['HTTP_COOKIE'] = cookie
+        except:
+            pass
index d5c61a7c15566dea963e2833911d6fd0ea755b4c..f9c1b99e4e27467f074ea122a1a4ee068063e95e 100644 (file)
@@ -214,6 +214,9 @@ if DEBUG and DEBUG_TOOLBAR:
         'INTERCEPT_REDIRECTS': False,
     }
 
+if ENABLE_PIWIK:
+    MIDDLEWARE_CLASSES += ('panikweb.middleware.StripPiwikCookieMiddleware',)
+
 if STATSD_CLIENT != 'django_statsd.clients.null':
     MIDDLEWARE_CLASSES = (
             'django_statsd.middleware.GraphiteRequestTimingMiddleware',