diff --git a/tests/integration/test_filter.py b/tests/integration/test_filter.py index b42bb34..da75f6d 100644 --- a/tests/integration/test_filter.py +++ b/tests/integration/test_filter.py @@ -106,6 +106,18 @@ def test_decompress_gzip(tmpdir, httpbin): assert_is_json(decoded_response) +def test_decomptess_empty_body(tmpdir, httpbin): + url = httpbin.url + "/gzip" + request = Request(url, headers={"Accept-Encoding": ["gzip, deflate"]}, method="HEAD") + cass_file = str(tmpdir.join("gzip_empty_response.yaml")) + with vcr.use_cassette(cass_file, decode_compressed_response=True): + response = urlopen(request).read() + with vcr.use_cassette(cass_file) as cass: + decoded_response = urlopen(request).read() + assert_cassette_has_one_response(cass) + assert decoded_response == response + + def test_decompress_deflate(tmpdir, httpbin): url = httpbin.url + "/deflate" request = Request(url, headers={"Accept-Encoding": ["gzip, deflate"]}) diff --git a/vcr/filters.py b/vcr/filters.py index 8e00b64..df3dd30 100644 --- a/vcr/filters.py +++ b/vcr/filters.py @@ -150,6 +150,8 @@ def decode_response(response): """Returns decompressed body according to encoding using zlib. to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16 """ + if not body: + return "" if encoding == "gzip": return zlib.decompress(body, zlib.MAX_WBITS | 16) else: # encoding == 'deflate'