Commits

Robert Brewer committed f541c89

Fix for #542 (_cpwsgiserver should concatenate multiple incoming headers).

Comments (0)

Files changed (2)

 # de-dupe the list
 socket_errors_to_ignore = dict.fromkeys(socket_errors_to_ignore).keys()
 
+# These are lowercase because mimetools.Message uses lowercase keys.
+comma_separated_headers = [
+    'accept', 'accept-charset', 'accept-encoding', 'accept-language',
+    'accept-ranges', 'allow', 'cache-control', 'connection', 'content-encoding',
+    'content-language', 'expect', 'if-match', 'if-none-match', 'pragma',
+    'proxy-authenticate', 'te', 'trailer', 'transfer-encoding', 'upgrade',
+    'vary', 'via', 'warning', 'www-authenticate',
+    ]
 
 class HTTPRequest(object):
     
             return
         self.environ["CONTENT_LENGTH"] = cl or ""
         
-        for (k, v) in headers.items():
-            envname = "HTTP_" + k.upper().replace("-","_")
-            self.environ[envname] = v
+        for k in headers:
+            envname = "HTTP_" + k.upper().replace("-", "_")
+            if k in comma_separated_headers:
+                self.environ[envname] = ", ".join(headers.getheaders(k))
+            else:
+                self.environ[envname] = headers[k]
         self.ready = True
     
     def abort(self, status, msg=""):

test/test_core.py

 
     class Headers(Test):
         
+        def default(self, headername):
+            """Spit back out the value for the requested header."""
+            return cherrypy.request.headers[headername]
+        
         def doubledheaders(self):
             # From http://www.cherrypy.org/ticket/165:
             # "header field names should not be case sensitive sayes the rfc.
                           '=?utf-8?b?4oSrbmdzdHLDtm3ihKtuZ3N0csO2beKEq25nc3Ryw7Zt4oSrbmdzdHLDtm0=?='
                           '=?utf-8?b?4oSrbmdzdHLDtm3ihKtuZ3N0csO2beKEq25nc3Ryw7Zt4oSrbmdzdHLDtm0=?='
                           '=?utf-8?b?4oSrbmdzdHLDtm3ihKtuZ3N0csO2bQ==?=')
+        
+        # Test that two request headers are collapsed into one.
+        # See http://www.cherrypy.org/ticket/542.
+        self.getPage("/headers/Accept-Charset",
+                     headers=[("Accept-Charset", "iso-8859-5"),
+                              ("Accept-Charset", "unicode-1-1;q=0.8")])
+        self.assertBody("iso-8859-5, unicode-1-1;q=0.8")
     
     def testHTTPMethods(self):
         helper.webtest.methods_with_bodies = ("POST", "PUT", "PROPFIND")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.