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

iteration or callback support #165

Open
casperdcl opened this issue May 2, 2020 · 1 comment
Open

iteration or callback support #165

casperdcl opened this issue May 2, 2020 · 1 comment

Comments

@casperdcl
Copy link

Support

  • content streams (like requests.Response.iter_content), or
  • per-chunk callbacks (like urllib.urlretrieve(..., reporthook=...))
@casperdcl
Copy link
Author

casperdcl commented May 2, 2020

I think this comes down to creating a new class HTTPResponseCallback(http.client.HTTPResponse):

class HTTPResponseCallback(http.client.HTTPResponse):
    def __init__(..., callback=None):
         self.callback = callback
         ...
    def _readall_chunked(self):
		...
        while True:
            ...
            if callback:
				self.callback(len(chunk))

class HTTPConnectionWithTimeout(http.client.HTTPConnection):
    response_class = HTTPResponseCallback

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

No branches or pull requests

1 participant