Merge "Do not quote '+' for token header"
This commit is contained in:
commit
c26c6380d0
|
@ -42,6 +42,7 @@ LOG = logging.getLogger(__name__)
|
||||||
USER_AGENT = 'python-glanceclient'
|
USER_AGENT = 'python-glanceclient'
|
||||||
CHUNKSIZE = 1024 * 64 # 64kB
|
CHUNKSIZE = 1024 * 64 # 64kB
|
||||||
REQ_ID_HEADER = 'X-OpenStack-Request-ID'
|
REQ_ID_HEADER = 'X-OpenStack-Request-ID'
|
||||||
|
TOKEN_HEADERS = ['X-Auth-Token', 'X-Service-Token']
|
||||||
|
|
||||||
|
|
||||||
def encode_headers(headers):
|
def encode_headers(headers):
|
||||||
|
@ -61,16 +62,20 @@ def encode_headers(headers):
|
||||||
# Bug #1766235: According to RFC 8187, headers must be encoded as ASCII.
|
# Bug #1766235: According to RFC 8187, headers must be encoded as ASCII.
|
||||||
# So we first %-encode them to get them into range < 128 and then turn
|
# So we first %-encode them to get them into range < 128 and then turn
|
||||||
# them into ASCII.
|
# them into ASCII.
|
||||||
if six.PY2:
|
encoded_dict = {}
|
||||||
# incoming items may be unicode, so get them into something
|
for h, v in headers.items():
|
||||||
# the py2 version of urllib can handle before percent encoding
|
if v is not None:
|
||||||
encoded_dict = dict((urlparse.quote(encodeutils.safe_encode(h)),
|
# if the item is token, do not quote '+' as well.
|
||||||
urlparse.quote(encodeutils.safe_encode(v)))
|
safe = '+/' if h in TOKEN_HEADERS else '/'
|
||||||
for h, v in headers.items() if v is not None)
|
if six.PY2:
|
||||||
else:
|
# incoming items may be unicode, so get them into something
|
||||||
encoded_dict = dict((urlparse.quote(h), urlparse.quote(v))
|
# the py2 version of urllib can handle before percent encoding
|
||||||
for h, v in headers.items() if v is not None)
|
key = urlparse.quote(encodeutils.safe_encode(h), safe)
|
||||||
|
value = urlparse.quote(encodeutils.safe_encode(v), safe)
|
||||||
|
else:
|
||||||
|
key = urlparse.quote(h, safe)
|
||||||
|
value = urlparse.quote(v, safe)
|
||||||
|
encoded_dict[key] = value
|
||||||
return dict((encodeutils.safe_encode(h, encoding='ascii'),
|
return dict((encodeutils.safe_encode(h, encoding='ascii'),
|
||||||
encodeutils.safe_encode(v, encoding='ascii'))
|
encodeutils.safe_encode(v, encoding='ascii'))
|
||||||
for h, v in encoded_dict.items())
|
for h, v in encoded_dict.items())
|
||||||
|
|
|
@ -467,11 +467,11 @@ class TestClient(testtools.TestCase):
|
||||||
headers = self.mock.last_request.headers
|
headers = self.mock.last_request.headers
|
||||||
self.assertEqual(refreshed_token, headers['X-Auth-Token'])
|
self.assertEqual(refreshed_token, headers['X-Auth-Token'])
|
||||||
# regression check for bug 1448080
|
# regression check for bug 1448080
|
||||||
unicode_token = u'ni\xf1o'
|
unicode_token = u'ni\xf1o+'
|
||||||
http_client.auth_token = unicode_token
|
http_client.auth_token = unicode_token
|
||||||
http_client.get(path)
|
http_client.get(path)
|
||||||
headers = self.mock.last_request.headers
|
headers = self.mock.last_request.headers
|
||||||
# Bug #1766235: According to RFC 8187, headers must be
|
# Bug #1766235: According to RFC 8187, headers must be
|
||||||
# encoded as 7-bit ASCII, so expect to see only displayable
|
# encoded as 7-bit ASCII, so expect to see only displayable
|
||||||
# chars in percent-encoding
|
# chars in percent-encoding. The '+' char will be not be changed.
|
||||||
self.assertEqual(b'ni%C3%B1o', headers['X-Auth-Token'])
|
self.assertEqual(b'ni%C3%B1o+', headers['X-Auth-Token'])
|
||||||
|
|
Loading…
Reference in New Issue