From d5ae0717c059c7ad5b3093e0f4c15b035e640a07 Mon Sep 17 00:00:00 2001 From: dd32 Date: Tue, 5 Apr 2011 06:09:43 +0000 Subject: [PATCH] Streamline WP_Http_*::test() methods: Check basic SSL requirements, only allow filters to disable transports, not enable them after ::test() has failed. Props mdawaffe for the initial patch. See #16606 git-svn-id: http://svn.automattic.com/wordpress/trunk@17598 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 45 +++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 0aa38ce567..5845479aa4 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -742,19 +742,18 @@ class WP_Http_Fsockopen { * @return boolean False means this class can not be used, true means it can. */ function test( $args = array() ) { + if ( ! function_exists( 'fsockopen' ) ) + return false; + if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours return false; - $is_ssl = isset($args['ssl']) && $args['ssl']; + $is_ssl = isset( $args['ssl'] ) && $args['ssl']; - if ( ! $is_ssl && function_exists( 'fsockopen' ) ) - $use = true; - elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) ) - $use = true; - else - $use = false; + if ( $is_ssl && ! extension_loaded( 'openssl' ) ) + return false; - return apply_filters('use_fsockopen_transport', $use, $args); + return apply_filters( 'use_fsockopen_transport', true, $args ); } } @@ -925,11 +924,19 @@ class WP_Http_Streams { * * @return boolean False means this class can not be used, true means it can. */ - function test($args = array()) { - if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) ) + function test( $args = array() ) { + if ( ! function_exists( 'fopen' ) ) return false; - return apply_filters('use_streams_transport', true, $args); + if ( ! function_exists( 'ini_get' ) || true != ini_get( 'allow_url_fopen' ) ) + return false; + + $is_ssl = isset( $args['ssl'] ) && $args['ssl']; + + if ( $is_ssl && ! extension_loaded( 'openssl' ) ) + return false; + + return apply_filters( 'use_streams_transport', true, $args ); } } @@ -1308,11 +1315,19 @@ class WP_Http_Curl { * * @return boolean False means this class can not be used, true means it can. */ - function test($args = array()) { - if ( function_exists('curl_init') && function_exists('curl_exec') ) - return apply_filters('use_curl_transport', true, $args); + function test( $args = array() ) { + if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) + return false; - return false; + $is_ssl = isset( $args['ssl'] ) && $args['ssl']; + + if ( $is_ssl ) { + $curl_version = curl_version(); + if ( ! (CURL_VERSION_SSL & $curl_version['features']) ) // Does this cURL version support SSL requests? + return false; + } + + return apply_filters( 'use_curl_transport', true, $args ); } }