Skip to content
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

Don't use raw reads for gzipped or chunked encoding (fixes #28, #36) #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions sseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ def _connect(self):
self.resp.raise_for_status()

def iter_content(self):
def generate():
while True:
if hasattr(self.resp.raw, '_fp') and \
hasattr(self.resp.raw._fp, 'fp') and \
hasattr(self.resp.raw._fp.fp, 'read1'):
if hasattr(self.resp.raw, '_fp') and \
hasattr(self.resp.raw._fp, 'fp') and \
hasattr(self.resp.raw._fp.fp, 'read1') and \
not self.resp.raw.chunked and \
not self.resp.raw.getheader("Content-Encoding"):
def generate():
while True:
chunk = self.resp.raw._fp.fp.read1(self.chunk_size)
else:
# _fp is not available, this means that we cannot use short
# reads and this will block until the full chunk size is
# actually read
chunk = self.resp.raw.read(self.chunk_size)
if not chunk:
break
yield chunk

return generate()
if not chunk:
break
yield chunk
return generate()
else:
# short reads cannot be used, this will block until
# the full chunk size is actually read
return self.resp.iter_content(self.chunk_size)

def _event_complete(self):
return re.search(end_of_field, self.buf) is not None
Expand Down