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: https://develop.svn.wordpress.org/trunk@23607 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2013-03-04 04:47:39 +00:00
parent b87d12f45f
commit 86a9ca48a1

View File

@ -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();