Use bytearray to accumulate bytes from gzip
MODIFY
CHANGES.rst
CHANGES.rst
@@ -4,6 +4,8 @@ Changes
dev (master)
------------
+* Remove quadratic behavior within ``GzipDecoder.decompress()`` (Issue #1467)
+
* ... [Short description of non-trivial change.] (Issue #)

MODIFY
src/urllib3/response.py
src/urllib3/response.py
@@ -69,9 +69,9 @@ class GzipDecoder(object):
return getattr(self._obj, name)
def decompress(self, data):
- ret = b''
+ ret = bytearray()
if self._state == GzipDecoderState.SWALLOW_DATA or not data:
- return ret
+ return bytes(ret)
while True:
try:
ret += self._obj.decompress(data)
@@ -81,11 +81,11 @@ class GzipDecoder(object):
self._state = GzipDecoderState.SWALLOW_DATA
if previous_state == GzipDecoderState.OTHER_MEMBERS:
# Allow trailing garbage acceptable in other gzip clients
- return ret
+ return bytes(ret)
raise
data = self._obj.unused_data
if not data:
- return ret
+ return bytes(ret)
self._state = GzipDecoderState.OTHER_MEMBERS
self._obj = zlib.decompressobj(16 + zlib.MAX_WBITS)

Use bytearray to accumulate bytes from gzip (#1468)