From 46a4d2d295365b34e3459a9d0f1a0a4e539f04b7 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 4 Mar 2013 04:47:39 +0000 Subject: [PATCH] WP_HTTP: Return error responses from cURL for non-blocking requests. Contrary to popular belief, cURL's non-blocking requests are not exact non-blocking, we still wait for cURL to make the request before returning, so making this change aids in development debugging. Props SergeyBiryukov Fixes #23310 git-svn-id: http://core.svn.wordpress.org/trunk@23607 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 5a652b4e4e..4ad0d5f446 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -1206,6 +1206,16 @@ class WP_Http_Curl { // We don't need to return the body, so don't. Just execute request and return. if ( ! $r['blocking'] ) { curl_exec( $handle ); + + if ( $curl_error = curl_error( $handle ) ) { + curl_close( $handle ); + return new WP_Error( 'http_request_failed', $curl_error ); + } + if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { + curl_close( $handle ); + return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); + } + curl_close( $handle ); return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); } @@ -1219,10 +1229,14 @@ class WP_Http_Curl { // If no response if ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) { - if ( $curl_error = curl_error( $handle ) ) + if ( $curl_error = curl_error( $handle ) ) { + curl_close( $handle ); return new WP_Error( 'http_request_failed', $curl_error ); - if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) + } + if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) { + curl_close( $handle ); return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); + } } $response = array();