[Zope-Checkins] SVN: Zope/trunk/ Merged from 2.10 branch - Collector #2320: HTTPResponse setHeader lowercased keys but getHeader did not, causing lookups of 'Content-Type' to fail

Hanno Schlichting plone at hannosch.info
Sun May 6 15:58:14 EDT 2007


Log message for revision 75582:
  Merged from 2.10 branch - Collector #2320: HTTPResponse setHeader lowercased keys but getHeader did not, causing lookups of 'Content-Type' to fail
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
  U   Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2007-05-06 19:47:41 UTC (rev 75581)
+++ Zope/trunk/doc/CHANGES.txt	2007-05-06 19:58:13 UTC (rev 75582)
@@ -97,6 +97,9 @@
 
     Bugs Fixed
 
+      - Collector #2320: HTTPResponse setHeader lowercased keys but getHeader
+        did not, causing lookups of 'Content-Type' to fail
+
       - Collector #2307: ObjectCopiedEvent not dispatched to sublocations.
 
       - Collector #2298: webdav.Resource.COPY and webdav.Resource.MOVE did

Modified: Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2007-05-06 19:47:41 UTC (rev 75581)
+++ Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2007-05-06 19:58:13 UTC (rev 75582)
@@ -247,8 +247,7 @@
         Sets an HTTP return header "name" with value "value", clearing
         the previous value set for the header, if one exists. If the
         literal flag is true, the case of the header name is preserved,
-        otherwise word-capitalization will be performed on the header
-        name on output.'''
+        otherwise the header name will be lowercased.'''
 
         name = str(name)
         value = str(value)
@@ -260,6 +259,18 @@
         name = literal and name or key
         self.headers[name] = value
 
+    def getHeader(self, name, literal=0):
+        '''\
+        Get a header value
+
+        Returns the value associated with a HTTP return header, or
+        "None" if no such header has been set in the response
+        yet. If the literal flag is true, the case of the header name is
+        preserved, otherwise the header name will be lowercased.'''
+        key = name.lower()
+        name = literal and name or key
+        return self.headers.get(name, None)
+
     def addHeader(self, name, value):
         '''\
         Set a new HTTP return header with the given value, while retaining

Modified: Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py	2007-05-06 19:47:41 UTC (rev 75581)
+++ Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py	2007-05-06 19:58:13 UTC (rev 75582)
@@ -77,6 +77,23 @@
         response.appendHeader('XXX', 'foo')
         self.assertEqual(response.headers.get('xxx'), 'bar,\n\tfoo')
 
+    def test_setHeader(self):
+        response = self._makeOne()
+        response.setHeader('foo', 'bar')
+        self.assertEqual(response.getHeader('foo'), 'bar')
+        self.assertEqual(response.headers.get('foo'), 'bar')
+        response.setHeader('SPAM', 'eggs')
+        self.assertEqual(response.getHeader('spam'), 'eggs')
+        self.assertEqual(response.getHeader('SPAM'), 'eggs')
+
+    def test_setHeader_literal(self):
+        response = self._makeOne()
+        response.setHeader('foo', 'bar', literal=True)
+        self.assertEqual(response.getHeader('foo'), 'bar')
+        response.setHeader('SPAM', 'eggs', literal=True)
+        self.assertEqual(response.getHeader('SPAM', literal=True), 'eggs')
+        self.assertEqual(response.getHeader('spam'), None)
+
     def test_setStatus_ResourceLockedError(self):
         response = self._makeOne()
         from webdav.Lockable import ResourceLockedError



More information about the Zope-Checkins mailing list