Skip to content

Commit 558fff7

Browse files
authored
Merge pull request #123 from grypoB/content-length
Add support for response without Content-Length
2 parents 268d662 + fa01944 commit 558fff7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

adafruit_requests.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,24 @@ def _readinto(self, buf: bytearray) -> int:
288288
self._parse_headers()
289289
return 0
290290
self._remaining = http_chunk_size
291+
elif self._remaining is None:
292+
# the Content-Length is not provided in the HTTP header
293+
# so try parsing as long as their is data in the socket
294+
pass
291295
else:
292296
return 0
293297

294298
nbytes = len(buf)
295-
if nbytes > self._remaining:
296-
nbytes = self._remaining
299+
if self._remaining and nbytes > self._remaining:
300+
# if Content-Length was provided and remaining bytes larges than buffer
301+
nbytes = self._remaining # adjust read amount
297302

298303
read = self._read_from_buffer(buf, nbytes)
299304
if read == 0:
300305
read = self._recv_into(buf, nbytes)
301-
self._remaining -= read
306+
if self._remaining:
307+
# if Content-Length was provided, adjust the remaining amount to still read
308+
self._remaining -= read
302309

303310
return read
304311

0 commit comments

Comments
 (0)