From ff6a4875a822c7185dab82b0f1eb137a2a2e823c Mon Sep 17 00:00:00 2001 From: Ryan McCue Date: Wed, 6 Jul 2016 17:51:30 +0000 Subject: [PATCH] HTTP API: Switch back to returning an array. The array-compatibility object we started returning in r37428 unfortunately isn't enough like an array. In particular, `is_array()` checks fail, despite the object implementing ArrayAccess. Mea culpa. This moves the WP_HTTP_Response object to a new http_response key in the array, and changes the value back to an actual array. Fixes #37097. See #33055. Built from https://develop.svn.wordpress.org/trunk@37989 git-svn-id: http://core.svn.wordpress.org/trunk@37930 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 9 +- .../class-wp-http-requests-response.php | 98 +++---------------- wp-includes/version.php | 2 +- 3 files changed, 23 insertions(+), 86 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 510ae27208..c5de3e01d4 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -348,10 +348,14 @@ class WP_Http { $options['verify'] = apply_filters( 'https_ssl_verify', $options['verify'] ); try { - $response = Requests::request( $url, $headers, $data, $type, $options ); + $requests_response = Requests::request( $url, $headers, $data, $type, $options ); // Convert the response into an array - $response = new WP_HTTP_Requests_Response( $response, $r['filename'] ); + $http_response = new WP_HTTP_Requests_Response( $requests_response, $r['filename'] ); + $response = $http_response->to_array(); + + // Add the original object to the array. + $response['http_response'] = $http_response; } catch ( Requests_Exception $e ) { $response = new WP_Error( 'http_request_failed', $e->getMessage() ); @@ -382,6 +386,7 @@ class WP_Http { 'message' => false, ), 'cookies' => array(), + 'http_response' => null, ); } diff --git a/wp-includes/class-wp-http-requests-response.php b/wp-includes/class-wp-http-requests-response.php index d85dffc7e8..741d1d79bd 100644 --- a/wp-includes/class-wp-http-requests-response.php +++ b/wp-includes/class-wp-http-requests-response.php @@ -1,13 +1,13 @@ get_headers(); - - case 'body': - return $this->get_data(); - - case 'response': - return array( - 'code' => $this->get_status(), - 'message' => get_status_header_desc( $this->get_status() ), - ); - - case 'cookies': - return $this->get_cookies(); - - case 'filename': - return $this->filename; - } - - return null; - } - - /** - * Set an ArrayAccess value. - * - * This is for array access back-compat. - * - * @param string|int $key Array offset to set. - * @param mixed $value Value to set. - */ - public function offsetSet( $key, $value ) { - switch ( $key ) { - case 'headers': - $this->set_headers( $value ); - break; - - case 'body': - $this->set_data( $value ); - break; - - case 'response': - if ( isset( $value['code'] ) ) { - $this->set_status( $value['code'] ); - } - break; - - case 'filename': - $this->filename = $value; - break; - } - } - - /** - * Unset an ArrayAccess value. - * - * This is for array access back-compat. - * - * @param string|int $key Array offset to remove. - */ - public function offsetUnset( $key ) { - $this->offsetSet( $key, null ); + public function to_array() { + return array( + 'headers' => $this->get_headers(), + 'body' => $this->get_data(), + 'response' => array( + 'code' => $this->get_status(), + 'message' => get_status_header_desc( $this->get_status() ), + ), + 'cookies' => $this->get_cookies(), + 'filename' => $this->filename, + ); } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 0f695c7b57..f477f4b813 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta1-37988'; +$wp_version = '4.6-beta1-37989'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.