summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Gregorio <joe@bitworking.org>2015-03-03 08:15:04 -0500
committerJoe Gregorio <joe@bitworking.org>2015-03-03 08:15:04 -0500
commit71a3b7b206395564c1923e24f9da4b200b30d44e (patch)
tree7fcc9bd1a86db18b81645657585f01606edb388a
parentdf1cca48b204fc20fde1e49d7ad763394b01d931 (diff)
parent1cf37bd8f5ddc8ac629b07031f7c5341840b5b7e (diff)
downloadhttplib2-71a3b7b206395564c1923e24f9da4b200b30d44e.tar.gz
Merge pull request #296 from cganterh/master
There was a problem with headers when a binary string is passed (like b'Authorization').
-rw-r--r--python3/httplib2/__init__.py7
-rwxr-xr-xpython3/httplib2test.py6
2 files changed, 12 insertions, 1 deletions
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py
index 43f7419..b7b00b1 100644
--- a/python3/httplib2/__init__.py
+++ b/python3/httplib2/__init__.py
@@ -192,8 +192,13 @@ def safename(filename):
NORMALIZE_SPACE = re.compile(r'(?:\r\n)?[ \t]+')
def _normalize_headers(headers):
- return dict([ (key.lower(), NORMALIZE_SPACE.sub(value, ' ').strip()) for (key, value) in headers.items()])
+ return dict([ (_convert_byte_str(key).lower(), NORMALIZE_SPACE.sub(_convert_byte_str(value), ' ').strip()) for (key, value) in headers.items()])
+def _convert_byte_str(s):
+ if not isinstance(s, str):
+ return str(s, 'utf-8')
+ return s
+
def _parse_cache_control(headers):
retval = {}
if 'cache-control' in headers:
diff --git a/python3/httplib2test.py b/python3/httplib2test.py
index 5f786bd..246956a 100755
--- a/python3/httplib2test.py
+++ b/python3/httplib2test.py
@@ -1235,6 +1235,12 @@ class HttpPrivateTest(unittest.TestCase):
self.assertTrue('cache-control' in h)
self.assertTrue('other' in h)
self.assertEqual('Stuff', h['other'])
+
+ def testConvertByteStr(self):
+ with self.assertRaises(TypeError):
+ httplib2._convert_byte_str(4)
+ self.assertEqual('Hello World', httplib2._convert_byte_str(b'Hello World'))
+ self.assertEqual('Bye World', httplib2._convert_byte_str('Bye World'))
def testExpirationModelTransparent(self):
# Test that no-cache makes our request TRANSPARENT