@@ -711,7 +711,7 @@ def __init__(self, checksum):
711711 super ().__init__ ()
712712 self ._checksum = checksum
713713
714- def decompress (self , data ):
714+ def decompress (self , data , max_length = - 1 ):
715715 """Decompress the bytes.
716716
717717 Args:
@@ -721,7 +721,11 @@ def decompress(self, data):
721721 bytes: The decompressed bytes from ``data``.
722722 """
723723 self ._checksum .update (data )
724- return super ().decompress (data )
724+ try :
725+ return super ().decompress (data , max_length = max_length )
726+ except TypeError :
727+ # Fallback for urllib3 < 2.6.0 which lacks `max_length` support.
728+ return super ().decompress (data )
725729
726730
727731# urllib3.response.BrotliDecoder might not exist depending on whether brotli is
@@ -747,7 +751,7 @@ def __init__(self, checksum):
747751 self ._decoder = urllib3 .response .BrotliDecoder ()
748752 self ._checksum = checksum
749753
750- def decompress (self , data ):
754+ def decompress (self , data , max_length = - 1 ):
751755 """Decompress the bytes.
752756
753757 Args:
@@ -757,10 +761,19 @@ def decompress(self, data):
757761 bytes: The decompressed bytes from ``data``.
758762 """
759763 self ._checksum .update (data )
760- return self ._decoder .decompress (data )
764+ try :
765+ return self ._decoder .decompress (data , max_length = max_length )
766+ except TypeError :
767+ # Fallback for urllib3 < 2.6.0 which lacks `max_length` support.
768+ return self ._decoder .decompress (data )
761769
762770 def flush (self ):
763771 return self ._decoder .flush ()
764772
773+ @property
774+ def has_unconsumed_tail (self ) -> bool :
775+ return self ._decoder .has_unconsumed_tail
776+
777+
765778else : # pragma: NO COVER
766779 _BrotliDecoder = None # type: ignore # pragma: NO COVER
0 commit comments