mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Introduce wp_http_supports as a much less hacky replacement for the http_transport_(get|post)_debug hooks that plugins could have
been using to detect if things like ssl requests were working. See #17251 props mdawaffe git-svn-id: https://develop.svn.wordpress.org/trunk@17914 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -27,10 +27,6 @@
|
||||
*
|
||||
* 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
|
||||
* @subpackage HTTP
|
||||
* @since 2.7.0
|
||||
@@ -195,6 +191,34 @@ class WP_Http {
|
||||
return $this->_dispatch_request($url, $r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests which transports are capabable of supporting the request.
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @access private
|
||||
*
|
||||
* @param array $args Request arguments
|
||||
* @param string $url URL to Request
|
||||
*
|
||||
* @return string|false Class name for the first transport that claims to support the request. False if no transport claims to support the request.
|
||||
*/
|
||||
public function _get_first_available_transport( $args, $url = null ) {
|
||||
$request_order = array( 'curl', 'streams', 'fsockopen' );
|
||||
|
||||
// Loop over each transport on each HTTP request looking for one which will serve this request's needs
|
||||
foreach ( $request_order as $transport ) {
|
||||
$class = 'WP_HTTP_' . $transport;
|
||||
|
||||
// Check to see if this transport is a possibility, calls the transport statically
|
||||
if ( !call_user_func( array( $class, 'test' ), $args, $url ) )
|
||||
continue;
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a HTTP request to a supporting transport.
|
||||
*
|
||||
@@ -216,34 +240,25 @@ class WP_Http {
|
||||
* @param array $args Request arguments
|
||||
* @return array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error
|
||||
*/
|
||||
private function _dispatch_request($url, $args) {
|
||||
private function _dispatch_request( $url, $args ) {
|
||||
static $transports = array();
|
||||
|
||||
$request_order = array('curl', 'streams', 'fsockopen');
|
||||
$class = $this->_get_first_available_transport( $args, $url );
|
||||
if ( !$class )
|
||||
return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) );
|
||||
|
||||
// Loop over each transport on each HTTP request looking for one which will serve this requests needs
|
||||
foreach ( $request_order as $transport ) {
|
||||
$class = 'WP_HTTP_' . $transport;
|
||||
// Transport claims to support request, Instantate it and give it a whirl.
|
||||
if ( empty( $transports[$class] ) )
|
||||
$transports[$class] = new $class;
|
||||
|
||||
// Check to see if this transport is a possibility, calls the transport statically
|
||||
if ( ! call_user_func( array($class, 'test'), $args, $url) )
|
||||
continue;
|
||||
$response = $transports[$class]->request( $url, $args );
|
||||
|
||||
// Transport claims to support request, Instantate it and give it a whirl.
|
||||
if ( empty( $transports[ $transport ] ) )
|
||||
$transports[ $transport ] = new $class;
|
||||
do_action( 'http_api_debug', $response, 'response', $class );
|
||||
|
||||
$response = $transports[ $transport ]->request( $url, $args );
|
||||
if ( is_wp_error( $response ) )
|
||||
return $response;
|
||||
|
||||
do_action( 'http_api_debug', $response, 'response', $class );
|
||||
|
||||
if ( is_wp_error( $response ) )
|
||||
return $response;
|
||||
|
||||
return apply_filters( 'http_response', $response, $args, $url );
|
||||
}
|
||||
|
||||
return new WP_Error('http_failure', __('There are no HTTP transports available which can complete the requested request.') );
|
||||
return apply_filters( 'http_response', $response, $args, $url );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user