Opened 5 months ago
Closed 5 months ago
#63576 closed defect (bug) (reported-upstream)
API Requests sometimes lose body
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | HTTP API | Keywords: | |
| Focuses: | Cc: |
Description (last modified by )
In limited circumstances, HTTP requests made using wp-includes/Requests/src/Requests.php will incorrectly return an empty string as the response body, even though the request executed and returned a value in the response.
This happens when the returned value is PHP-falsey (for example, the string "0") - or in other words, when empty($value) evaluates to true in PHP.
I've encountered this issue in production, so the diff we went with is attached.
Attachments (1)
Change History (4)
#1
@
5 months ago
I think patches for Requests go in the upstream library here: https://github.com/WordPress/Requests
#2
@
5 months ago
- Description modified (diff)
- Version trunk deleted
(See line 742 on the GitHub repository if you want to create a pull request.)
The substr() function should always return a string. I think simply checking for an empty string would suffice:
if ($body !== '')
#3
@
5 months ago
- Milestone Awaiting Review deleted
- Resolution set to reported-upstream
- Status changed from new to closed
Apparently I was wrong about returning a string (in all versions of PHP), but the pull request is on GitHub for further discussion:
https://github.com/WordPress/Requests/pull/933
Patch for WP::Requests class to handle '0' response body