Requests icon indicating copy to clipboard operation
Requests copied to clipboard

max_bytes not respected in a performant manner

Open jrfnl opened this issue 4 years ago • 4 comments
trafficstars

Note: this is a recreation of PR #337, which was closed due to the branch rename and the remote no longer existing. Please see PR #337 for the original discussion on the PR.

With some testing I was noticing that a request for 100 byes from a 10MB file was timing out after 5 seconds.

Turns out that the cause was that Requests downloads the full 10MB file in order to return the first 100 bytes of it.

This PR simply aborts the connection when enough bytes have been read from the stream.

/cc @dd32

jrfnl avatar Jun 18 '21 09:06 jrfnl

Updates needed for this PR to be mergeable:

schlessera avatar Aug 20 '21 08:08 schlessera

* PHP constants should be used for the cURL error codes, instead of magic numbers (see [licurl error codes](https://curl.se/libcurl/c/libcurl-errors.html) & [curl constants](https://www.php.net/manual/en/curl.constants.php)).

This point has been addressed in the recent rebase to solve merge conflicts.

This PR does however still needs tests.

jrfnl avatar Oct 11 '21 15:10 jrfnl

@jrfnl I've added tests for this. The tests could verify the problem, i.e. the tests failed without the fix, and they now succeed with the fix. I've drastically increased the amount of bytes being requested by the server to force the issue, but with the fix in place, the download should still only be the first few bytes anyway.

schlessera avatar Nov 12 '21 08:11 schlessera

Rebased without changes to get it past an imaginary merge conflict.

jrfnl avatar Feb 07 '22 20:02 jrfnl

Rebased without changes to get it past an imaginary merge conflict.

jrfnl avatar Apr 24 '23 09:04 jrfnl