1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

filters.py: Make decompression robust towards decompressed input

This commit is contained in:
Sebastian Pipping
2023-06-21 02:19:58 +02:00
parent 8c6b1fdf38
commit 438a65426b
2 changed files with 32 additions and 2 deletions

View File

@@ -153,9 +153,15 @@ def decode_response(response):
if not body:
return ""
if encoding == "gzip":
return zlib.decompress(body, zlib.MAX_WBITS | 16)
try:
return zlib.decompress(body, zlib.MAX_WBITS | 16)
except zlib.error:
return body # assumes that the data was already decompressed
else: # encoding == 'deflate'
return zlib.decompress(body)
try:
return zlib.decompress(body)
except zlib.error:
return body # assumes that the data was already decompressed
# Deepcopy here in case `headers` contain objects that could
# be mutated by a shallow copy and corrupt the real response.