Commit 4091e00d authored by Hanno Schlichting's avatar Hanno Schlichting

Merged from 2.10 branch - Collector #2320: HTTPResponse setHeader lowercased...

Merged from 2.10 branch - Collector #2320: HTTPResponse setHeader lowercased keys but getHeader did not, causing lookups of 'Content-Type' to fail
parent 6f3b6501
......@@ -97,6 +97,9 @@ Zope Changes
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
......
......@@ -247,8 +247,7 @@ class HTTPResponse(BaseResponse):
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 @@ class HTTPResponse(BaseResponse):
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
......
......@@ -77,6 +77,23 @@ class HTTPResponseTests(unittest.TestCase):
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
......
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