diff --git a/CHANGELOG.md b/CHANGELOG.md index 814577805..c4f9ff6dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release History +## Unreleased: mitmproxy next + +* fix some responses not being decoded properly if the encoding was uppercase #4735 (@Mattwmaster58) + ## 4 August 2021: mitmproxy 7.0.2 * Fix a WebSocket crash introduced in 7.0.1 (@mhils) diff --git a/mitmproxy/net/encoding.py b/mitmproxy/net/encoding.py index 9ed2163a4..854931e60 100644 --- a/mitmproxy/net/encoding.py +++ b/mitmproxy/net/encoding.py @@ -52,6 +52,7 @@ def decode( """ if encoded is None: return None + encoding = encoding.lower() global _cache cached = ( @@ -67,7 +68,7 @@ def decode( decoded = custom_decode[encoding](encoded) except KeyError: decoded = codecs.decode(encoded, encoding, errors) # type: ignore - if encoding in ("gzip", "deflate", "br", "zstd"): + if encoding in ("gzip", "deflate", "deflateraw", "br", "zstd"): _cache = CachedDecode(encoded, encoding, errors, decoded) return decoded except TypeError: @@ -108,6 +109,7 @@ def encode(decoded: Union[None, str, bytes], encoding, errors='strict') -> Union """ if decoded is None: return None + encoding = encoding.lower() global _cache cached = ( @@ -123,7 +125,7 @@ def encode(decoded: Union[None, str, bytes], encoding, errors='strict') -> Union encoded = custom_encode[encoding](decoded) except KeyError: encoded = codecs.encode(decoded, encoding, errors) # type: ignore - if encoding in ("gzip", "deflate", "br", "zstd"): + if encoding in ("gzip", "deflate", "deflateraw", "br", "zstd"): _cache = CachedDecode(encoded, encoding, errors, decoded) return encoded except TypeError: @@ -216,7 +218,7 @@ custom_decode = { "identity": identity, "gzip": decode_gzip, "deflate": decode_deflate, - "deflateRaw": decode_deflate, + "deflateraw": decode_deflate, "br": decode_brotli, "zstd": decode_zstd, } @@ -225,7 +227,7 @@ custom_encode = { "identity": identity, "gzip": encode_gzip, "deflate": encode_deflate, - "deflateRaw": encode_deflate, + "deflateraw": encode_deflate, "br": encode_brotli, "zstd": encode_zstd, } diff --git a/test/mitmproxy/net/test_encoding.py b/test/mitmproxy/net/test_encoding.py index 55d7d6f38..328306e1d 100644 --- a/test/mitmproxy/net/test_encoding.py +++ b/test/mitmproxy/net/test_encoding.py @@ -17,6 +17,7 @@ def test_identity(encoder): @pytest.mark.parametrize("encoder", [ 'gzip', + 'GZIP', 'br', 'deflate', 'zstd',