Browse Source

Merge "Fix setdefault() for swob's HeaderKeyDict."

changes/76/43476/2
Jenkins 8 years ago
committed by Gerrit Code Review
parent
commit
3dfc094662
  1. 5
      swift/common/swob.py
  2. 3
      swift/proxy/controllers/base.py
  3. 17
      test/unit/common/test_swob.py

5
swift/common/swob.py

@ -281,6 +281,11 @@ class HeaderKeyDict(dict):
def get(self, key, default=None):
return dict.get(self, key.title(), default)
def setdefault(self, key, value=None):
if key not in self:
self[key] = value
return self[key]
def _resp_status_property():
"""

3
swift/proxy/controllers/base.py

@ -473,8 +473,7 @@ class Controller(object):
headers = HeaderKeyDict(additional) if additional else HeaderKeyDict()
if transfer:
self.transfer_headers(orig_req.headers, headers)
if 'x-timestamp' not in headers:
headers['x-timestamp'] = normalize_timestamp(time.time())
headers.setdefault('x-timestamp', normalize_timestamp(time.time()))
if orig_req:
referer = orig_req.as_referer()
else:

17
test/unit/common/test_swob.py

@ -81,6 +81,23 @@ class TestHeaderKeyDict(unittest.TestCase):
self.assertEquals(headers['content-length'], '20')
self.assertEquals(headers['CONTENT-LENGTH'], '20')
def test_setdefault(self):
headers = swift.common.swob.HeaderKeyDict()
# it gets set
headers.setdefault('x-rubber-ducky', 'the one')
self.assertEquals(headers['X-Rubber-Ducky'], 'the one')
# it has the right return value
ret = headers.setdefault('x-boat', 'dinghy')
self.assertEquals(ret, 'dinghy')
ret = headers.setdefault('x-boat', 'yacht')
self.assertEquals(ret, 'dinghy')
# shouldn't crash
headers.setdefault('x-sir-not-appearing-in-this-request', None)
def test_del_contains(self):
headers = swift.common.swob.HeaderKeyDict()
headers['Content-Length'] = 0

Loading…
Cancel
Save