REST API: Do not send response body if status is 204 or body is null.

Status code 204 should indicate no response body is sent. Previously, a "null" string was sent, which MacOS Safari would try to parse as JSON and thereby fail to complete the request.

Props TimothyBlynJacobs, andizer, matthias.thiel.
Fixes #43691.


Built from https://develop.svn.wordpress.org/trunk@45809


git-svn-id: http://core.svn.wordpress.org/trunk@45620 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
K. Adam White 2019-08-15 19:56:55 +00:00
parent b75420443c
commit 8dcc10693f
2 changed files with 6 additions and 1 deletions

View File

@ -405,6 +405,11 @@ class WP_REST_Server {
*/
$result = apply_filters( 'rest_pre_echo_response', $result, $this, $request );
// The 204 response shouldn't have a body.
if ( 204 === $code || null === $result ) {
return null;
}
$result = wp_json_encode( $result );
$json_error_message = $this->get_json_last_error();

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45808';
$wp_version = '5.3-alpha-45809';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.