Opened 12 years ago
Closed 12 years ago
#28919 closed enhancement (fixed)
WP_Http needs to support custom HTTP status code messages
| Reported by: | ragulka | Owned by: | dd32 |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.1 |
| Component: | HTTP API | Version: | 3.9.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
WP_Http has currently no way to get the the status message for a custom HTTP status code, because it uses get_status_header_desc to map the status code to a built-in status message. This provides a problem when interacting with APIs that use custom HTTP status codes for error messages, for example, because there is no way to know the error message.
I suggest there be a filter around https://core.trac.wordpress.org/browser/tags/3.9.1/src/wp-includes/class-http.php#L1402 so it's possible for developers to supply their own status message. Something like:
$response['message'] = apply_filters( 'http_status_header_description', get_status_header_desc($response['code']), $response['code'], $response );
Providing the response code and full response array would allow developers to see the full context when filtering.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Currently the Streams transport passes through the message field from the server, it's just the cURL transport that uses
get_status_header_desc().Since we're already parsing the headers manually, and pulling out the response field, it makes sense to just use the same processing code for both Streams and cURL for this.