- // Append cookies that were used in this request to the response
- if ( ! empty( $r['cookies'] ) ) {
- $cookies_set = wp_list_pluck( $response['cookies'], 'name' );
- foreach ( $r['cookies'] as $cookie ) {
- if ( ! in_array( $cookie->name, $cookies_set ) && $cookie->test( $url ) ) {
- $response['cookies'][] = $cookie;
- }
+ if ( ! $r['blocking'] ) {
+ return array(
+ 'headers' => array(),
+ 'body' => '',
+ 'response' => array(
+ 'code' => false,
+ 'message' => false,
+ ),
+ 'cookies' => array(),
+ 'http_response' => null,
+ );
+ }
+
+ /**
+ * Filters the HTTP API response immediately before the response is returned.
+ *
+ * @since 2.9.0
+ *
+ * @param array $response HTTP response.
+ * @param array $r HTTP request arguments.
+ * @param string $url The request URL.
+ */
+ return apply_filters( 'http_response', $response, $r, $url );
+ }
+
+ /**
+ * Normalizes cookies for using in Requests.
+ *
+ * @since 4.6.0
+ * @access public
+ * @static
+ *
+ * @param array $cookies List of cookies to send with the request.
+ * @return Requests_Cookie_Jar Cookie holder object.
+ */
+ public static function normalize_cookies( $cookies ) {
+ $cookie_jar = new Requests_Cookie_Jar();
+
+ foreach ( $cookies as $name => $value ) {
+ if ( $value instanceof WP_Http_Cookie ) {
+ $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes() );
+ } elseif ( is_scalar( $value ) ) {
+ $cookie_jar[ $name ] = new Requests_Cookie( $name, $value );