Changeset 45809
- Timestamp:
- 08/15/2019 07:55:13 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r45687 r45809 405 405 */ 406 406 $result = apply_filters( 'rest_pre_echo_response', $result, $this, $request ); 407 408 // The 204 response shouldn't have a body. 409 if ( 204 === $code || null === $result ) { 410 return null; 411 } 407 412 408 413 $result = wp_json_encode( $result ); -
trunk/tests/phpunit/tests/rest-api/rest-server.php
r43652 r45809 1145 1145 } 1146 1146 1147 /** 1148 * @ticket 43691 1149 */ 1150 public function test_does_not_echo_body_for_null_responses() { 1151 register_rest_route( 1152 'test-ns', 1153 '/test', 1154 array( 1155 'methods' => array( 'GET' ), 1156 'callback' => function () { 1157 return new WP_REST_Response(); 1158 }, 1159 ) 1160 ); 1161 1162 $result = rest_get_server()->serve_request( '/test-ns/test' ); 1163 1164 $this->assertNull( $result ); 1165 $this->assertEquals( '', rest_get_server()->sent_body ); 1166 } 1167 1168 /** 1169 * @ticket 43691 1170 */ 1171 public function test_does_not_echo_body_for_responses_with_204_status() { 1172 register_rest_route( 1173 'test-ns', 1174 '/test', 1175 array( 1176 'methods' => array( 'GET' ), 1177 'callback' => function () { 1178 return new WP_REST_Response( 'data', 204 ); 1179 }, 1180 ) 1181 ); 1182 1183 $result = rest_get_server()->serve_request( '/test-ns/test' ); 1184 1185 $this->assertNull( $result ); 1186 $this->assertEquals( '', rest_get_server()->sent_body ); 1187 } 1188 1147 1189 public function _validate_as_integer_123( $value, $request, $key ) { 1148 1190 if ( ! is_int( $value ) ) {
Note: See TracChangeset
for help on using the changeset viewer.