Merge "Do not decode headers in v1/images.py"

This commit is contained in:
Jenkins
2013-06-05 23:09:07 +00:00
committed by Gerrit Code Review
2 changed files with 12 additions and 14 deletions
+12 -3
View File
@@ -77,11 +77,20 @@ class ImageManager(base.Manager):
def _image_meta_to_headers(self, fields):
headers = {}
fields_copy = copy.deepcopy(fields)
ensure_unicode = utils.ensure_unicode
# NOTE(flaper87): Convert to str, headers
# that are not instance of basestring. All
# headers will be encoded later, before the
# request is sent.
def to_str(value):
if not isinstance(value, basestring):
return str(value)
return value
for key, value in fields_copy.pop('properties', {}).iteritems():
headers['x-image-meta-property-%s' % key] = ensure_unicode(value)
headers['x-image-meta-property-%s' % key] = to_str(value)
for key, value in fields_copy.iteritems():
headers['x-image-meta-%s' % key] = ensure_unicode(value)
headers['x-image-meta-%s' % key] = to_str(value)
return headers
@staticmethod
-11
View File
@@ -460,17 +460,6 @@ class ImageManagerTest(testtools.TestCase):
expect = [('PUT', '/v1/images/1', expect_headers, None)]
self.assertEqual(self.api.calls, expect)
def test_image_meta_to_headers_encoding(self):
# NOTE(flaper87): This doesn't make much sense
# _image_meta_to_headers decodes headers that will
# then be encoded before sending the request. If
# everything works as expected, there shouldn't be
# any need to enforce unicode in headers at this step.
# Will get rid of that in a separate patch.
fields = {"name": "ni\xc3\xb1o"}
headers = self.mgr._image_meta_to_headers(fields)
self.assertEqual(headers["x-image-meta-name"], u"ni\xf1o")
def test_image_meta_from_headers_encoding(self):
fields = {"x-image-meta-name": "ni\xc3\xb1o"}
headers = self.mgr._image_meta_from_headers(fields)