Commit b24bb10c authored by Hanno Schlichting's avatar Hanno Schlichting

Collector #2320: HTTPResponse setHeader lowercased keys but getHeader did not,...

Collector #2320: HTTPResponse setHeader lowercased keys but getHeader did not, causing lookups of 'Content-Type' to fail
parent 80c31373
...@@ -8,6 +8,9 @@ Zope Changes ...@@ -8,6 +8,9 @@ Zope Changes
Bugs fixed 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 - Collector #2321: Skip trusted proxies when extracting the client IP
address from the request. address from the request.
......
...@@ -247,8 +247,7 @@ class HTTPResponse(BaseResponse): ...@@ -247,8 +247,7 @@ class HTTPResponse(BaseResponse):
Sets an HTTP return header "name" with value "value", clearing Sets an HTTP return header "name" with value "value", clearing
the previous value set for the header, if one exists. If the the previous value set for the header, if one exists. If the
literal flag is true, the case of the header name is preserved, literal flag is true, the case of the header name is preserved,
otherwise word-capitalization will be performed on the header otherwise the header name will be lowercased.'''
name on output.'''
name = str(name) name = str(name)
value = str(value) value = str(value)
key = name.lower() key = name.lower()
...@@ -259,6 +258,18 @@ class HTTPResponse(BaseResponse): ...@@ -259,6 +258,18 @@ class HTTPResponse(BaseResponse):
name = literal and name or key name = literal and name or key
self.headers[name] = value 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): def addHeader(self, name, value):
'''\ '''\
Set a new HTTP return header with the given value, while retaining Set a new HTTP return header with the given value, while retaining
......
...@@ -77,6 +77,23 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -77,6 +77,23 @@ class HTTPResponseTests(unittest.TestCase):
response.appendHeader('XXX', 'foo') response.appendHeader('XXX', 'foo')
self.assertEqual(response.headers.get('xxx'), 'bar,\n\tfoo') 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): def test_setStatus_ResourceLockedError(self):
response = self._makeOne() response = self._makeOne()
from webdav.Lockable import ResourceLockedError from webdav.Lockable import ResourceLockedError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment