Skip to content

Commit

Permalink
Merge pull request #278 from kevin1024/empty_response_body
Browse files Browse the repository at this point in the history
Empty response body
  • Loading branch information
kevin1024 authored Oct 2, 2016
2 parents df5f608 + 1fbd65a commit 2454aa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/integration/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ def test_body(tmpdir, httpbin_both):
assert content == requests.get(url).content


def test_get_empty_content_type_json(tmpdir, httpbin_both):
'''Ensure GET with application/json content-type and empty request body doesn't crash'''
url = httpbin_both + '/status/200'
headers = {'Content-Type': 'application/json'}

with vcr.use_cassette(str(tmpdir.join('get_empty_json.yaml')), match_on=('body',)):
status = requests.get(url, headers=headers).status_code

with vcr.use_cassette(str(tmpdir.join('get_empty_json.yaml')), match_on=('body',)):
assert status == requests.get(url, headers=headers).status_code


def test_effective_url(tmpdir, httpbin_both):
'''Ensure that the effective_url is captured'''
url = httpbin_both.url + '/redirect-to?url=/html'
Expand Down
3 changes: 2 additions & 1 deletion vcr/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def _transform_json(body):
# Request body is always a byte string, but json.loads() wants a text
# string. RFC 7159 says the default encoding is UTF-8 (although UTF-16
# and UTF-32 are also allowed: hmmmmm).
return json.loads(body.decode('utf-8'))
if body:
return json.loads(body.decode('utf-8'))


_xml_header_checker = _header_checker('text/xml')
Expand Down

0 comments on commit 2454aa2

Please sign in to comment.