Merge "Fix up requests so we can send non-RFC-compliant headers on py3"
This commit is contained in:
commit
4f320bd034
@ -74,8 +74,10 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# requests version 1.2.3 try to encode headers in ascii, preventing
|
# requests version 1.2.3 try to encode headers in ascii, preventing
|
||||||
# utf-8 encoded header to be 'prepared'
|
# utf-8 encoded header to be 'prepared'. This also affects all
|
||||||
if StrictVersion(requests.__version__) < StrictVersion('2.0.0'):
|
# (or at least most) versions of requests on py3
|
||||||
|
if StrictVersion(requests.__version__) < StrictVersion('2.0.0') \
|
||||||
|
or not six.PY2:
|
||||||
from requests.structures import CaseInsensitiveDict
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
def prepare_unicode_headers(self, headers):
|
def prepare_unicode_headers(self, headers):
|
||||||
|
@ -18,6 +18,7 @@ import unittest
|
|||||||
import time
|
import time
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves import configparser
|
from six.moves import configparser
|
||||||
|
|
||||||
import swiftclient
|
import swiftclient
|
||||||
@ -446,6 +447,22 @@ class TestFunctional(unittest.TestCase):
|
|||||||
self.assertEqual('45.67', headers.get('x-object-meta-float'))
|
self.assertEqual('45.67', headers.get('x-object-meta-float'))
|
||||||
self.assertEqual('False', headers.get('x-object-meta-bool'))
|
self.assertEqual('False', headers.get('x-object-meta-bool'))
|
||||||
|
|
||||||
|
def test_post_object_unicode_header_name(self):
|
||||||
|
self.conn.post_object(self.containername,
|
||||||
|
self.objectname,
|
||||||
|
{u'x-object-meta-\U0001f44d': u'\U0001f44d'})
|
||||||
|
|
||||||
|
# Note that we can't actually read this header back on py3; see
|
||||||
|
# https://bugs.python.org/issue37093
|
||||||
|
# We'll have to settle for just testing that the POST doesn't blow up
|
||||||
|
# with a UnicodeDecodeError
|
||||||
|
if six.PY2:
|
||||||
|
headers = self.conn.head_object(
|
||||||
|
self.containername, self.objectname)
|
||||||
|
self.assertIn(u'x-object-meta-\U0001f44d', headers)
|
||||||
|
self.assertEqual(u'\U0001f44d',
|
||||||
|
headers.get(u'x-object-meta-\U0001f44d'))
|
||||||
|
|
||||||
def test_copy_object(self):
|
def test_copy_object(self):
|
||||||
self.conn.put_object(
|
self.conn.put_object(
|
||||||
self.containername, self.objectname, self.test_data)
|
self.containername, self.objectname, self.test_data)
|
||||||
|
Loading…
Reference in New Issue
Block a user