Skip to content

Add support for response without Content-Length #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,24 @@ def _readinto(self, buf: bytearray) -> int:
self._parse_headers()
return 0
self._remaining = http_chunk_size
elif self._remaining is None:
# the Content-Length is not provided in the HTTP header
# so try parsing as long as their is data in the socket
pass
else:
return 0

nbytes = len(buf)
if nbytes > self._remaining:
nbytes = self._remaining
if self._remaining and nbytes > self._remaining:
# if Content-Length was provided and remaining bytes larges than buffer
nbytes = self._remaining # adjust read amount

read = self._read_from_buffer(buf, nbytes)
if read == 0:
read = self._recv_into(buf, nbytes)
self._remaining -= read
if self._remaining:
# if Content-Length was provided, adjust the remaining amount to still read
self._remaining -= read

return read

Expand Down