-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Add Request.WithLimit #271
Comments
Hey @gavv, I was looking into this issue. We can use this https://go.dev/play/p/BJKXGLnwiL5
Even if the response exceeds the max size, we can return data(resp) until the max and return error/warning after reading the response. Are we separating functionality where we just report an error when it exceeds or return the data and error? I'd like to give this a go |
Hi,
This sounds good, I was thinking about the same behavior.
Using MaxBytesReader is nice idea. On the other hand, there are two thoughts why I think it's better to implement the check manually in bodyWrapper:
BTW, there is another issue related to bodyWrapper: #245 |
Would you like to be assigned? |
Yes @gavv |
Postponing this issue until #342 is merged. See #321 (comment) |
Hey @gavv, I can take this one if it's available. |
@aliziyacevik #342 was just merged today, so yes, you're welcome. In the new implementation, I think it should be enough to modify httpReadNext and httpReadFull methods (but please re-check). |
@aliziyacevik Hi, do you still have plans on the issue? |
Hi @gavv, if no one is working on this issue, Can I take this up? |
Hi @gavv can I work on this ? |
Add new method Request.WithLimit that set's a limit for maximum number of bytes that can be retrieved from response body.
It can be helpful to interrupt early on abnormally large response (e.g. mistakenly trying to read infinite chunked response into memory), thus avoiding insane memory consumption by tests, swapping, etc.
Request.WithLimit should store the provided limit into a private field of Request. Later, in Request.retryRequest we should check if limit is set, and if so, pass this limit to bodyWrapper when we're wrapping response body.
Then, we should teach bodyWrapper to handle the limit. When the limit is set and bodyWrapper detected that it read more bytes than desired, it should abort read and return error that explains that limit is exceed and what is the limit.
Ideally error message should contain limit both in bytes and in human readable form, like "5 MB".
New method should have documentation comment with code example and two tests:
The text was updated successfully, but these errors were encountered: