File tree Expand file tree Collapse file tree 3 files changed +8
-4
lines changed
Expand file tree Collapse file tree 3 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1+ Fixed decoding Gzip-encoded responses which specified ``x-gzip `` content-encoding.
Original file line number Diff line number Diff line change @@ -208,7 +208,9 @@ def _get_decoder(mode: str) -> ContentDecoder:
208208 if "," in mode :
209209 return MultiDecoder (mode )
210210
211- if mode == "gzip" :
211+ # According to RFC 9110 section 8.4.1.3, recipients should
212+ # consider x-gzip equivalent to gzip
213+ if mode in ("gzip" , "x-gzip" ):
212214 return GzipDecoder ()
213215
214216 if brotli is not None and mode == "br" :
@@ -280,7 +282,7 @@ def get(self, n: int) -> bytes:
280282
281283
282284class BaseHTTPResponse (io .IOBase ):
283- CONTENT_DECODERS = ["gzip" , "deflate" ]
285+ CONTENT_DECODERS = ["gzip" , "x-gzip" , " deflate" ]
284286 if brotli is not None :
285287 CONTENT_DECODERS += ["br" ]
286288 if zstd is not None :
Original file line number Diff line number Diff line change @@ -229,14 +229,15 @@ def test_chunked_decoding_deflate2(self) -> None:
229229 assert r .read () == b""
230230 assert r .read () == b""
231231
232- def test_chunked_decoding_gzip (self ) -> None :
232+ @pytest .mark .parametrize ("content_encoding" , ["gzip" , "x-gzip" ])
233+ def test_chunked_decoding_gzip (self , content_encoding : str ) -> None :
233234 compress = zlib .compressobj (6 , zlib .DEFLATED , 16 + zlib .MAX_WBITS )
234235 data = compress .compress (b"foo" )
235236 data += compress .flush ()
236237
237238 fp = BytesIO (data )
238239 r = HTTPResponse (
239- fp , headers = {"content-encoding" : "gzip" }, preload_content = False
240+ fp , headers = {"content-encoding" : content_encoding }, preload_content = False
240241 )
241242
242243 assert r .read (1 ) == b"f"
You can’t perform that action at this time.
0 commit comments