[Zope-Checkins] SVN: Zope/branches/2.10/ 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:47:42 EDT 2007
Log message for revision 75581:
Collector #2320: HTTPResponse setHeader lowercased keys but getHeader did not, causing lookups of 'Content-Type' to fail
Changed:
U Zope/branches/2.10/doc/CHANGES.txt
U Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py
U Zope/branches/2.10/lib/python/ZPublisher/tests/testHTTPResponse.py
-=-
Modified: Zope/branches/2.10/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.10/doc/CHANGES.txt 2007-05-06 19:47:41 UTC (rev 75580)
+++ Zope/branches/2.10/doc/CHANGES.txt 2007-05-06 19:47:41 UTC (rev 75581)
@@ -8,6 +8,9 @@
Bugs fixed
+ - Collector #2320: HTTPResponse setHeader lowercased keys but getHeader
+ did not, causing lookups of 'Content-Type' to fail
+
- Collector #2321: Skip trusted proxies when extracting the client IP
address from the request.
Modified: Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py 2007-05-06 19:47:41 UTC (rev 75580)
+++ Zope/branches/2.10/lib/python/ZPublisher/HTTPResponse.py 2007-05-06 19:47:41 UTC (rev 75581)
@@ -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)
key = name.lower()
@@ -259,6 +258,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/branches/2.10/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/branches/2.10/lib/python/ZPublisher/tests/testHTTPResponse.py 2007-05-06 19:47:41 UTC (rev 75580)
+++ Zope/branches/2.10/lib/python/ZPublisher/tests/testHTTPResponse.py 2007-05-06 19:47:41 UTC (rev 75581)
@@ -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