Skip to content

Commit e55e975

Browse files
committed
close(): fix exception and enable fast-close
1 parent cd34a7e commit e55e975

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

adafruit_requests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,23 @@ def _throw_away(self, nbytes: int) -> None:
226226
while to_read > 0:
227227
to_read -= self._recv_into(buf, to_read)
228228

229-
def close(self) -> None:
229+
def close(self, fast: bool = False) -> None:
230230
"""Drain the remaining ESP socket buffers. We assume we already got what we wanted."""
231231
if not self.socket:
232232
return
233233
# Make sure we've read all of our response.
234-
if self._cached is None:
234+
if self._cached is None and not fast:
235235
if self._remaining and self._remaining > 0:
236236
self._throw_away(self._remaining)
237237
elif self._chunked:
238238
while True:
239239
chunk_header = bytes(self._readto(b"\r\n")).split(b";", 1)[0]
240+
if not chunk_header:
241+
break
240242
chunk_size = int(bytes(chunk_header), 16)
241243
if chunk_size == 0:
242244
break
243245
self._throw_away(chunk_size + 2)
244-
self._parse_headers()
245246
if self._session:
246247
# pylint: disable=protected-access
247248
self._session._connection_manager.free_socket(self.socket)

0 commit comments

Comments
 (0)