diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php
index 07d2f6248e..9d8ccae22c 100644
--- a/wp-includes/class-http.php
+++ b/wp-includes/class-http.php
@@ -27,10 +27,6 @@
*
* Debugging includes several actions, which pass different variables for debugging the HTTP API.
*
- * http_transport_get_debug - gives working, nonblocking, and blocking transports.
- *
- * http_transport_post_debug - 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 );
}
/**
diff --git a/wp-includes/http.php b/wp-includes/http.php
index 63cf97d1f9..e17878fc10 100644
--- a/wp-includes/http.php
+++ b/wp-includes/http.php
@@ -191,4 +191,34 @@ function wp_remote_retrieve_body(&$response) {
return $response['body'];
}
-?>
\ No newline at end of file
+/**
+ * Determins if there is an HTTP Transport that can process this request.
+ *
+ * @since 3.2.0
+ *
+ * @param array $capabilities Array of capabilities to test or a wp_remote_request() $args array.
+ * @param string $url Optional. If given, will check if the URL requires SSL and adds that requirement to the capabilities array.
+ *
+ * @return bool
+ */
+function wp_http_supports( $capabilities = array(), $url = null ) {
+ $objFetchSite = _wp_http_get_object();
+
+ $capabilities = wp_parse_args( $capabilities );
+
+ $count = count( $capabilities );
+
+ // If we have a numeric $capabilities array, spoof a wp_remote_request() associative $args array
+ if ( $count && count( array_filter( array_keys( $capabilities ), 'is_numeric' ) ) == $count ) {
+ $capabilities = array_combine( array_values( $capabilities ), array_fill( 0, $count, true ) );
+ }
+
+ if ( $url && !isset( $capabilities['ssl'] ) ) {
+ $scheme = parse_url( $url, PHP_URL_SCHEME );
+ if ( 'https' == $scheme || 'ssl' == $scheme ) {
+ $capabilities['ssl'] = true;
+ }
+ }
+
+ return (bool) $objFetchSite->_get_first_available_transport( $capabilities );
+}