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
This commit is contained in:
parent
581975e9bf
commit
46a4d2d295
|
@ -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,11 +1229,15 @@ 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();
|
||||
$response['code'] = curl_getinfo( $handle, CURLINFO_HTTP_CODE );
|
||||
|
|
Loading…
Reference in New Issue