WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#28919 closed enhancement (fixed)

WP_Http needs to support custom HTTP status code messages

Reported by: ragulka Owned by: dd32
Milestone: 4.1 Priority: normal
Severity: normal Version: 3.9.1
Component: HTTP API Keywords:
Focuses: Cc:
PR Number:

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.

Change History (2)

#1 @dd32
5 years ago

  • Milestone changed from Awaiting Review to 4.1
  • Owner set to dd32
  • Status changed from new to accepted

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.

#2 @dd32
5 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 29848:

Return the correct server response for the 'message' response field from the server.
Previously this would use the generic message corresponding to the response code, which isn't always accurate. Since we're already parsing the headers, we can simply return that directly (This also has the benefit that it's the same code for both Streams and Curl header handling).
Fixes #28919

Note: See TracTickets for help on using tickets.