Opened 13 months ago
Closed 13 months ago
#63576 closed defect (bug) (reported-upstream)
API Requests sometimes lose body
| Reported by: | granthony | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | HTTP API | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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
@
13 months ago
I think patches for Requests go in the upstream library here: https://github.com/WordPress/Requests
#2
@
13 months ago
- Description modified (diff)
- Version trunk
(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
@
13 months ago
- Milestone Awaiting Review
- Resolution → reported-upstream
- Status new → 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
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch for WP::Requests class to handle '0' response body