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.
|
// We don't need to return the body, so don't. Just execute request and return.
|
||||||
if ( ! $r['blocking'] ) {
|
if ( ! $r['blocking'] ) {
|
||||||
curl_exec( $handle );
|
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 );
|
curl_close( $handle );
|
||||||
return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
|
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 no response
|
||||||
if ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) {
|
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 );
|
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.' ) );
|
return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = array();
|
$response = array();
|
||||||
|
|
Loading…
Reference in New Issue