Process incoming headers. URL-decode if necessary.
authorAntony Chazapis <chazapis@gmail.com>
Wed, 23 Nov 2011 12:04:48 +0000 (14:04 +0200)
committerAntony Chazapis <chazapis@gmail.com>
Wed, 23 Nov 2011 12:04:48 +0000 (14:04 +0200)
Refs #1511

pithos/middleware/__init__.py
pithos/middleware/header.py [new file with mode: 0644]
pithos/settings.py.dist

index dcd24c5..4c195f2 100644 (file)
@@ -1,2 +1,3 @@
 from log import LoggingConfigMiddleware
 from log import LoggingConfigMiddleware
+from header import URLEncodedHeadersMiddleware
 from auth import AuthMiddleware
 from auth import AuthMiddleware
diff --git a/pithos/middleware/header.py b/pithos/middleware/header.py
new file mode 100644 (file)
index 0000000..fe4d00b
--- /dev/null
@@ -0,0 +1,43 @@
+# Copyright 2011 GRNET S.A. All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+# 
+#   1. Redistributions of source code must retain the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer.
+# 
+#   2. Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+# 
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+# 
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
+
+from urllib import quote, unquote
+
+
+class URLEncodedHeadersMiddleware(object):
+    def process_request(self, request):
+        meta = request.META
+        for k, v in meta.copy().iteritems():
+            if k.startswith('HTTP_') and ('%' in k or '%' in v):
+                del(meta[k])
+                meta[unquote(k)] = v
index fda15ee..be3ecb8 100644 (file)
@@ -130,6 +130,7 @@ MIDDLEWARE_CLASSES = (
 #    'django.middleware.csrf.CsrfViewMiddleware',
 #    'django.contrib.auth.middleware.AuthenticationMiddleware',
 #    'django.contrib.messages.middleware.MessageMiddleware',
 #    'django.middleware.csrf.CsrfViewMiddleware',
 #    'django.contrib.auth.middleware.AuthenticationMiddleware',
 #    'django.contrib.messages.middleware.MessageMiddleware',
+    'pithos.middleware.URLEncodedHeadersMiddleware',
     'pithos.middleware.LoggingConfigMiddleware',
     'pithos.middleware.AuthMiddleware'
 )
     'pithos.middleware.LoggingConfigMiddleware',
     'pithos.middleware.AuthMiddleware'
 )