Requests
Requests copied to clipboard
max_bytes not respected in a performant manner
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
Updates needed for this PR to be mergeable:
- Tests need to be added.
- PHP constants should be used for the cURL error codes, instead of magic numbers (see licurl error codes & curl constants).
* 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 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.
Rebased without changes to get it past an imaginary merge conflict.
Rebased without changes to get it past an imaginary merge conflict.