Make WordPress Core

Ticket #16606: 16606.7.patch

File 16606.7.patch, 4.6 KB (added by hakre, 12 years ago)
  • wp-includes/class-http.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk
     
    746746         * @return boolean False means this class can not be used, true means it can.
    747747         */
    748748        function test( $args = array() ) {
    749                 if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours
    750                         return false;
     749                $is_ssl = !empty( $args['ssl'] );
    751750
    752                 $is_ssl = isset($args['ssl']) && $args['ssl'];
     751                // check if fsockopen has been disabled for 12 hours
     752                $use = ( $option = get_option( 'disable_fsockopen', 0 ) ) && time() - $option > 43200; // 43200 = 12 hours
    753753
    754                 if ( ! $is_ssl && function_exists( 'fsockopen' ) )
    755                         $use = true;
    756                 elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) )
    757                         $use = true;
    758                 else
    759                         $use = false;
     754                // check if there is a function named fsockopen
     755                if ( $use )
     756                        $use = function_exists( 'fsockopen' );
    760757
    761                 return apply_filters('use_fsockopen_transport', $use, $args);
     758                // check if openssl is available for SSL transports
     759                if  ( $use && $is_ssl )
     760                        $use = extension_loaded( 'openssl' );
     761
     762                return (bool) apply_filters('use_fsockopen_transport', $use, $args );
    762763        }
    763764}
    764765
     
    929930         *
    930931         * @return boolean False means this class can not be used, true means it can.
    931932         */
    932         function test($args = array()) {
    933                 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
    934                         return false;
     933        function test( $args = array(), $url = null ) {
     934                $is_ssl = !empty( $args['ssl'] );
    935935
    936                 return apply_filters('use_streams_transport', true, $args);
     936                $scheme = empty($url) ? 'http' : strtolower( parse_url( $url, PHP_URL_SCHEME ) );
     937
     938                $allowed_schemes = array( 'http', 'https' );
     939
     940                // check if the requested scheme is allowed
     941                $use = in_array( $scheme, $allowed_schemes );
     942
     943                // check if the fopen function exists
     944                if ( $use )
     945                        $use = function_exists( 'fopen' );
     946
     947                // check if url fopen is allowed
     948                if ( $use )
     949                        $use = function_exists( 'ini_get' ) && ini_get( 'allow_url_fopen' );
     950
     951                // check if requested scheme has a stream wrapper
     952                if ( $use )
     953                        $use = in_array( $scheme, stream_get_wrappers() );
     954
     955                // check specifically against openssl extension
     956                if ( $use && $is_ssl )
     957                        $use = extension_loaded( 'openssl' );
     958
     959                // check if streams actually support ssl
     960                if ( $use && $is_ssl )
     961                        $use = in_array( 'ssl', stream_get_transports() );
     962
     963                return (bool) apply_filters( 'use_streams_transport', $use, $args, $url );
    937964        }
    938965}
    939966
     
    10641091                                $theBody = http_chunked_decode($theBody);
    10651092                }
    10661093
    1067                 if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) )
    1068                         $theBody = http_inflate( $theBody );
     1094                if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) {
     1095                        if ( http_support( HTTP_SUPPORT_ENCODINGS ) ) {
     1096                                $theBody = http_inflate( $theBody );
     1097                        } else {
     1098                                $theBody = WP_Http_Encoding::decompress( $theBody );
     1099                        }
     1100                }
    10691101
    10701102                if ( $r['stream'] ) {
    10711103                        if ( !WP_DEBUG )
     
    10971129         * @return boolean False means this class can not be used, true means it can.
    10981130         */
    10991131        function test($args = array()) {
    1100                 return apply_filters('use_http_extension_transport', function_exists('http_request'), $args );
     1132
     1133                $is_ssl = !empty( $args['ssl'] );
     1134
     1135                // check if there is a function named http_support
     1136                $use = function_exists( 'http_support' );
     1137
     1138                // check if there is support for requests
     1139                if ( $use )
     1140                        $use = http_support( HTTP_SUPPORT_REQUESTS );
     1141
     1142                // check if there is support for SSL requests
     1143                if ( $use && $is_ssl )
     1144                        $use = http_support( HTTP_SUPPORT_SSLREQUESTS );
     1145
     1146                return (bool) apply_filters( 'use_http_extension_transport', $use, $args );
    11011147        }
    11021148}
    11031149
     
    13131359         * @return boolean False means this class can not be used, true means it can.
    13141360         */
    13151361        function test($args = array()) {
    1316                 if ( function_exists('curl_init') && function_exists('curl_exec') )
    1317                         return apply_filters('use_curl_transport', true, $args);
    13181362
    1319                 return false;
     1363                $is_ssl = !empty( $args['ssl'] );
     1364
     1365                // check if there is a function named curl_init
     1366                $use = function_exists( 'curl_init' );
     1367
     1368                // check if there is a function named curl_exec
     1369                if ( $use )
     1370                        $use = function_exists( 'curl_exec' );
     1371
     1372                // check if openssl is available for SSL transports
     1373                if  ( $use && $is_ssl )
     1374                        $use = extension_loaded( 'openssl' );
     1375
     1376                return (bool) apply_filters( 'use_curl_transport', $use, $args );
    13201377        }
    13211378}
    13221379