Skip to content

Commit

Permalink
Merge "Convert headers to bytes testing request_headers"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 28, 2014
2 parents 7ba4595 + befd86a commit c6bf163
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions requests_mock/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,25 @@ def _match_url(self, request):

def _match_headers(self, request):
for k, vals in six.iteritems(self._request_headers):

try:
header = request.headers[k]
except KeyError:
return False
else:
if header != vals:
# NOTE(jamielennox): This seems to be a requests 1.2/2
# difference, in 2 they are just whatever the user inputted in
# 1 they are bytes. Let's optionally handle both and look at
# removing this when we depend on requests 2.
if not isinstance(k, six.text_type):
return False

try:
header = request.headers[k.encode('utf-8')]
except KeyError:
return False

if header != vals:
return False

return True

def _match(self, request):
Expand Down

0 comments on commit c6bf163

Please sign in to comment.