Skip to content

python-ecosys/urequests: add streaming API support and cache standard responses #426

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

Closed
wants to merge 0 commits into from

Conversation

mkomon
Copy link

@mkomon mkomon commented May 30, 2021

As the title says.

@mkomon
Copy link
Author

mkomon commented May 30, 2021

By the way I am using urequests with these two commits with lichess.org API and all works well, both standard and streaming API requests. Without this patch streaming requests don't work at all as they read only the immediate response and close the socket immediately.

while chunk:
data += chunk
chunk = self.raw.read()
return data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to combine all data here? Why not just return the result of the first read? The caller must anyway keep calling this function until it has all data.

Copy link
Author

@mkomon mkomon Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that makes sense and the loop just adds an unnecessary read. I will test it with return self.raw.read() and report back.

if stream:
resp.raw.setblocking(False)
else:
resp.content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it makes sense to pre-read the content here. Some uses of this may not need the content and then it shouldn't waste time and memory retrieving it.

Copy link
Author

@mkomon mkomon Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not considered such use case but it makes total sense. There is no need to read the response like the original requests package does. I'll remove 9b5d30c. (removed with a force-push since it was the last commit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants