[rh:requests] Do not allocate 2GB on read (#13603)

Fixes c2ff2dbaec

Authored by: Grub4K
pull/13610/head
Simon Sawicki 4 weeks ago committed by GitHub
parent e99c0b838a
commit c316416b97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -143,7 +143,9 @@ class RequestsResponseAdapter(Response):
# Work around issue with `.read(amt)` then `.read()` # Work around issue with `.read(amt)` then `.read()`
# See: https://github.com/urllib3/urllib3/issues/3636 # See: https://github.com/urllib3/urllib3/issues/3636
if amt is None: if amt is None:
amt = (1 << 31) - 1 # Python 3.9 preallocates the whole read buffer, read in chunks
read_chunk = functools.partial(self.fp.read, 1 << 20, decode_content=True)
return b''.join(iter(read_chunk, b''))
# Interact with urllib3 response directly. # Interact with urllib3 response directly.
return self.fp.read(amt, decode_content=True) return self.fp.read(amt, decode_content=True)

Loading…
Cancel
Save