python-httplib2/python-httplib2-0.9-binary-header-python3.patch
Kevin Fenzi 2ddc623a07 - Add patch to fix http over proxy. Fixes bug #857514
- Add patch to fix CVE-2013-2037. Fixes bug #958640
- Add patch to fix binary headers in python3. Fixes bug #1205127
2015-04-03 13:26:39 -06:00

60 lines
2.2 KiB
Diff

From 93ba12c7d7483af5374ba5f0e62a46ddc5e1ffe2 Mon Sep 17 00:00:00 2001
From: i026e <klev.paul@gmail.com>
Date: Wed, 17 Dec 2014 11:25:07 +0300
Subject: [PATCH 1/2] Update __init__.py
There is a problem with headers when a binary string is passed (like b'Authorization')
I've added a function to decode such strings.
It is not an elegant solution, but it works for me
---
python3/httplib2/__init__.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
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:
From 1cf37bd8f5ddc8ac629b07031f7c5341840b5b7e Mon Sep 17 00:00:00 2001
From: Cristobal <cganterh@gmail.com>
Date: Mon, 2 Mar 2015 21:00:03 -0300
Subject: [PATCH 2/2] Added unit test for _convert_byte_str in
python3/httplib2test.py.
---
python3/httplib2test.py | 6 ++++++
1 file changed, 6 insertions(+)
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 @@ def testNormalizeHeaders(self):
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