Skip to content

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

Closed
mkomon wants to merge 0 commit into
micropython:masterfrom
mkomon:master
Closed

python-ecosys/urequests: add streaming API support and cache standard responses#426
mkomon wants to merge 0 commit into
micropython:masterfrom
mkomon:master

Conversation

@mkomon

@mkomon mkomon commented May 30, 2021

Copy link
Copy Markdown

As the title says.

@mkomon

mkomon commented May 30, 2021

Copy link
Copy Markdown
Author

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.

Comment thread python-ecosys/urequests/urequests.py Outdated
while chunk:
data += chunk
chunk = self.raw.read()
return data

Copy link
Copy Markdown
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.

@mkomon mkomon Jun 1, 2021

Copy link
Copy Markdown
Author

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.

Comment thread python-ecosys/urequests/urequests.py Outdated
if stream:
resp.raw.setblocking(False)
else:
resp.content

Copy link
Copy Markdown
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.

@mkomon mkomon Jun 1, 2021

Copy link
Copy Markdown
Author

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