Ticket #16606: 16606.4.patch

File 16606.4.patch, 1.6 KB (added by hakre, 2 years ago)

All checks, result truly filterable line in WP_Http_Curl::test() and WP_Http_ExtHttp::test()

  • wp-includes/class-http.php

    ### Eclipse Workspace Patch 1.0
    #P wordpress-trunk
     
    868868         * 
    869869         * @return boolean False means this class can not be used, true means it can. 
    870870         */ 
    871         function test($args = array()) { 
    872                 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) ) 
    873                         return false; 
     871        function test( $args = array(), $url = '' ) { 
     872                $is_ssl = isset( $args['ssl'] ) && $args['ssl']; 
    874873 
    875                 return apply_filters('use_streams_transport', true, $args); 
     874                $scheme = emprty($url) ? 'http' : strtolower( parse_url( $url, PHP_URL_SCHEME ) ); 
     875                 
     876                $allowed_streams = array('http', 'https'); 
     877                 
     878                // check if the requested scheme is allowed  
     879                $use = in_array( $scheme, $allowed_streams); 
     880                 
     881                // check if the fopen function exists 
     882                if ( $use ) 
     883                        $use = function_exists('fopen'); 
     884                 
     885                // check if url fopen is allowed 
     886                if ( $use ) 
     887                        $use = function_exists('ini_get') && ini_get('allow_url_fopen'); 
     888 
     889                // check if requested scheme has a stream wrapper 
     890                if ( $use ) 
     891                        $use = in_array( $scheme, stream_get_wrappers() ); 
     892 
     893                // check specifically agains openssl extension 
     894                if ( $use && $is_ssl ) 
     895                        $use = extension_loaded( 'openssl' ); 
     896 
     897                // check if streams actually support ssl  
     898                if ( $use && $is_ssl ) 
     899                        $use = in_array( 'ssl', stream_get_transports() ); 
     900 
     901                return (bool) apply_filters( 'use_streams_transport', $use, $args ); 
    876902        } 
    877903} 
    878904