Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
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
  • Loading branch information
i026e committed Dec 17, 2014
1 parent df1cca4 commit 93ba12c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 93ba12c

Please sign in to comment.