[rh:urllib] Eagerly release BytesIO responses (#17717)

Authored by: doe1080
This commit is contained in:
doe1080
2026-09-27 19:54:19 +02:00
committed by GitHub
parent 9dd5e68cd7
commit f9eee6ba62
+3 -1
View File
@@ -313,7 +313,9 @@ class UrllibResponseAdapter(Response):
# urllib's addinfourl does not close the underlying fp automatically when fully read
if isinstance(underlying, io.BytesIO):
# data URLs or in-memory responses (e.g. gzip/deflate/brotli decoded)
if underlying.tell() >= len(underlying.getbuffer()):
with underlying.getbuffer() as view:
fully_read = underlying.tell() >= len(view)
if fully_read:
self.close()
elif isinstance(underlying, io.BufferedReader) and amt is None:
# file URLs.