HTTP API debug and action for curl object. Props jacobsantos. see #8727

git-svn-id: https://develop.svn.wordpress.org/trunk@10281 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-12-30 22:45:51 +00:00
parent 948e542722
commit 601ba7bcf0

View File

@ -30,6 +30,15 @@
* requirement, it will be easy to add the static keyword to the code. It is not * requirement, it will be easy to add the static keyword to the code. It is not
* as easy to convert a function to a method after enough code uses the old way. * as easy to convert a function to a method after enough code uses the old way.
* *
* Debugging includes several actions, which pass different variables for
* debugging the HTTP API.
*
* <strong>http_transport_get_debug</strong> - gives working, nonblocking, and
* blocking transports.
*
* <strong>http_transport_post_debug</strong> - gives working, nonblocking, and
* blocking transports.
*
* @package WordPress * @package WordPress
* @subpackage HTTP * @subpackage HTTP
* @since 2.7 * @since 2.7
@ -114,6 +123,9 @@ class WP_Http {
} }
} }
if( has_filter('http_transport_get_debug') )
do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport);
if ( isset($args['blocking']) && !$args['blocking'] ) if ( isset($args['blocking']) && !$args['blocking'] )
return $nonblocking_transport; return $nonblocking_transport;
else else
@ -156,6 +168,9 @@ class WP_Http {
} }
} }
if( has_filter('http_transport_post_debug') )
do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport);
if ( isset($args['blocking']) && !$args['blocking'] ) if ( isset($args['blocking']) && !$args['blocking'] )
return $nonblocking_transport; return $nonblocking_transport;
else else
@ -257,10 +272,16 @@ class WP_Http {
$transports = WP_Http::_postTransport($r); $transports = WP_Http::_postTransport($r);
} }
if( has_action('http_api_debug') )
do_action('http_api_debug', $transports, 'transports_list');
$response = array( 'headers' => array(), 'body' => '', 'response' => array('code', 'message') ); $response = array( 'headers' => array(), 'body' => '', 'response' => array('code', 'message') );
foreach( (array) $transports as $transport ) { foreach( (array) $transports as $transport ) {
$response = $transport->request($url, $r); $response = $transport->request($url, $r);
if( has_action('http_api_debug') )
do_action( 'http_api_debug', $response, 'response', get_class($transport) );
if( ! is_wp_error($response) ) if( ! is_wp_error($response) )
return $response; return $response;
} }
@ -409,7 +430,7 @@ class WP_Http {
if ( $hasChunk ) { if ( $hasChunk ) {
if ( empty($match[1]) ) { if ( empty($match[1]) ) {
return new WP_Error('http_chunked_decode', __('Does not appear to be chunked encoded or body is malformed.') ); return $body;
} }
$length = hexdec( $match[1] ); $length = hexdec( $match[1] );
@ -426,7 +447,7 @@ class WP_Http {
break; break;
} }
} else { } else {
return new WP_Error('http_chunked_decode', __('Does not appear to be chunked encoded or body is malformed.') ); return $body;
} }
} while ( false === $done ); } while ( false === $done );
} }
@ -1019,6 +1040,8 @@ class WP_Http_Curl {
else else
curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
do_action_ref_array( 'http_api_curl', &$handle );
if ( ! $r['blocking'] ) { if ( ! $r['blocking'] ) {
curl_exec( $handle ); curl_exec( $handle );
curl_close( $handle ); curl_close( $handle );