Merge pull request #4741 from Mattwmaster58/main

case insensitive encoding
This commit is contained in:
Maximilian Hils 2021-08-10 08:18:56 +02:00 committed by GitHub
commit ab6f1ebb44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View File

@ -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)

View File

@ -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,
}

View File

@ -17,6 +17,7 @@ def test_identity(encoder):
@pytest.mark.parametrize("encoder", [
'gzip',
'GZIP',
'br',
'deflate',
'zstd',