Do not decode headers in v1/images.py
v1.images._image_meta_to_headers currently encodes headers as a way to ensure they're an instance of basestring. This is not necessary since headers will be encoded later during the request. Also, all data within the client should be already decoded. Fixes bug: #1187013 Change-Id: I80525adbc6e9e576cfad5b576090ef9ee574c1cf
This commit is contained in:
@@ -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
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user