Prioritize transports differently for non-blocking requests. fixes #8086

git-svn-id: https://develop.svn.wordpress.org/trunk@9572 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-11-08 22:35:00 +00:00
parent 9094473f4a
commit 28b8dc875e
1 changed files with 49 additions and 21 deletions

View File

@ -84,25 +84,40 @@ class WP_Http {
* @since 2.7 * @since 2.7
* @access private * @access private
* *
* @param array $args Request args, default us an empty array
* @return object|null Null if no transports are available, HTTP transport object. * @return object|null Null if no transports are available, HTTP transport object.
*/ */
function &_getTransport() { function &_getTransport( $args = array() ) {
static $working_transport; static $working_transport, $blocking_transport, $nonblocking_transport;
if ( is_null($working_transport) ) { if ( is_null($working_transport) ) {
if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) {
$working_transport[] = new WP_Http_ExtHttp(); $working_transport['exthttp'] = new WP_Http_ExtHttp();
else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) ) $blocking_transport[] = &$working_transport['exthttp'];
$working_transport[] = new WP_Http_Curl(); } else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) ) {
else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) $working_transport['curl'] = new WP_Http_Curl();
$working_transport[] = new WP_Http_Streams(); $blocking_transport[] = &$working_transport['curl'];
else if ( true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true) ) } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) {
$working_transport[] = new WP_Http_Fopen(); $working_transport['streams'] = new WP_Http_Streams();
else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) $blocking_transport[] = &$working_transport['streams'];
$working_transport[] = new WP_Http_Fsockopen(); } else if ( true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true) ) {
$working_transport['fopen'] = new WP_Http_Fopen();
$blocking_transport[] = &$working_transport['fopen'];
} else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) {
$working_transport['fsockopen'] = new WP_Http_Fsockopen();
$blocking_transport[] = &$working_transport['fsockopen'];
}
foreach ( array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport ) {
if ( isset($working_transport[$transport]) )
$nonblocking_transport[] = &$working_transport[$transport];
}
} }
return $working_transport; if ( isset($args['blocking']) && !$args['blocking'] )
return $nonblocking_transport;
else
return $blocking_transport;
} }
/** /**
@ -117,21 +132,34 @@ class WP_Http {
* @since 2.7 * @since 2.7
* @access private * @access private
* *
* @param array $args Request args, default us an empty array
* @return object|null Null if no transports are available, HTTP transport object. * @return object|null Null if no transports are available, HTTP transport object.
*/ */
function &_postTransport() { function &_postTransport( $args = array() ) {
static $working_transport; static $working_transport, $blocking_transport, $nonblocking_transport;
if ( is_null($working_transport) ) { if ( is_null($working_transport) ) {
if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) {
$working_transport[] = new WP_Http_ExtHttp(); $working_transport[] = new WP_Http_ExtHttp();
else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) $blocking_transport[] = &$working_transport['exthttp'];
} else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) {
$working_transport[] = new WP_Http_Streams(); $working_transport[] = new WP_Http_Streams();
else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) $blocking_transport[] = &$working_transport['streams'];
} else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) {
$working_transport[] = new WP_Http_Fsockopen(); $working_transport[] = new WP_Http_Fsockopen();
$blocking_transport[] = &$working_transport['fsockopen'];
}
foreach ( array('streams', 'fsockopen', 'exthttp') as $transport ) {
if ( isset($working_transport[$transport]) )
$nonblocking_transport[] = &$working_transport[$transport];
}
} }
return $working_transport; if ( isset($args['blocking']) && !$args['blocking'] )
return $nonblocking_transport;
else
return $blocking_transport;
} }
/** /**
@ -214,7 +242,7 @@ class WP_Http {
} }
if ( is_null($r['body']) ) { if ( is_null($r['body']) ) {
$transports = WP_Http::_getTransport(); $transports = WP_Http::_getTransport($r);
} else { } else {
if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
$r['body'] = http_build_query($r['body'], null, '&'); $r['body'] = http_build_query($r['body'], null, '&');
@ -222,7 +250,7 @@ class WP_Http {
$r['headers']['Content-Length'] = strlen($r['body']); $r['headers']['Content-Length'] = strlen($r['body']);
} }
$transports = WP_Http::_postTransport(); $transports = WP_Http::_postTransport($r);
} }
$response = array( 'headers' => array(), 'body' => '', 'response' => array('code', 'message') ); $response = array( 'headers' => array(), 'body' => '', 'response' => array('code', 'message') );