Make WordPress Core

Changeset 10864


Ignore:
Timestamp:
04/03/2009 06:23:13 PM (17 years ago)
Author:
ryan
Message:

Proxy support. Props DD32. see #4011

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/http.php

    r10810 r10864  
    119119                }
    120120
    121                 if( has_filter('http_transport_get_debug') )
     121                if ( has_filter('http_transport_get_debug') )
    122122                        do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport);
    123123
     
    167167                }
    168168
    169                 if( has_filter('http_transport_post_debug') )
     169                if ( has_filter('http_transport_post_debug') )
    170170                        do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport);
    171171
     
    244244                // Determine if this is a https call and pass that on to the transport functions
    245245                // so that we can blacklist the transports that do not support ssl verification
    246                 if ( $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl' )
    247                         $r['ssl'] = true;
    248                 else
    249                         $r['ssl'] = false;
    250 
    251                 // Determine if this request is to OUR install of WordPress
    252                 if ( stristr(get_bloginfo('url'), $arrURL['host']) )
    253                         $r['local'] = true;
    254                 else
    255                         $r['local'] = false;
     246                $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
     247
     248                // Determine if this request is to OUR install of WordPress
     249                $homeURL = parse_url(get_bloginfo('url'));
     250                $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
     251                unset($homeURL);
    256252
    257253                if ( is_null( $r['headers'] ) )
     
    276272                WP_Http::buildCookieHeader( $r );
    277273
    278                 if( WP_Http_Encoding::is_available() )
     274                if ( WP_Http_Encoding::is_available() )
    279275                        $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
    280276
     
    297293                }
    298294
    299                 if( has_action('http_api_debug') )
     295                if ( has_action('http_api_debug') )
    300296                        do_action('http_api_debug', $transports, 'transports_list');
    301297
    302298                $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
    303                 foreach( (array) $transports as $transport ) {
     299                foreach ( (array) $transports as $transport ) {
    304300                        $response = $transport->request($url, $r);
    305301
    306                         if( has_action('http_api_debug') )
     302                        if ( has_action('http_api_debug') )
    307303                                do_action( 'http_api_debug', $response, 'response', get_class($transport) );
    308304
    309                         if( ! is_wp_error($response) )
     305                        if ( ! is_wp_error($response) )
    310306                                return $response;
    311307                }
     
    420416                        if ( !empty( $value ) ) {
    421417                                $key = strtolower( $key );
    422                                 if ( isset( $newheaders[$key] ) ) {
     418
     419                                if ( isset( $newheaders[$key] ) )
    423420                                        $newheaders[$key] = array( $newheaders[$key], trim( $value ) );
    424                                 } else {
     421                                else
    425422                                        $newheaders[$key] = trim( $value );
    426                                 }
     423
    427424                                if ( 'set-cookie' == strtolower( $key ) )
    428425                                        $cookies[] = new WP_Http_Cookie( $value );
     
    449446                if ( ! empty($r['cookies']) ) {
    450447                        $cookies_header = '';
    451                         foreach ( (array) $r['cookies'] as $cookie ) {
     448                        foreach ( (array) $r['cookies'] as $cookie )
    452449                                $cookies_header .= $cookie->getHeaderValue() . '; ';
    453                         }
    454450                        $cookies_header = substr( $cookies_header, 0, -2 );
    455451                        $r['headers']['cookie'] = $cookies_header;
     
    495491                                $body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n");
    496492
    497                                 if( "0" == trim($body) )
     493                                if ( "0" == trim($body) )
    498494                                        return $parsedBody; // Ignore footer headers.
    499495                        } else {
     
    511507         * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL in your wp-config.php file
    512508         * and this will only allow localhost and your blog to make requests. The constant
    513          * WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests.
     509         * WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests. The format of the
     510         * WP_ACCESSABLE_HOSTS constant is a comma separated list of hostnames to allow.
    514511         *
    515512         * @since 2.8.0
     
    538535                        return false;
    539536
    540                 $home = parse_url( get_bloginfo('site_url') );
     537                $home = parse_url( get_option('siteurl') );
    541538
    542539                // Don't block requests back to ourselves by default
    543                 if ( $uri == 'localhost' || $uri == $home['host'] )
     540                if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] )
    544541                        return apply_filters('block_local_requests', false);
    545542
    546                 if ( defined('WP_ACCESSABLE_HOSTS') && is_array( WP_ACCESSABLE_HOSTS ) && in_array( $check['host'], WP_ACCESSABLE_HOSTS ) ) {
    547                                 return false;
    548                 }
    549 
    550                 return true;
     543                if ( !defined('WP_ACCESSABLE_HOSTS') )
     544                        return true;
     545
     546                static $accessable_hosts;
     547                if ( null == $accessable_hosts )
     548                        $accessable_hosts = preg_split('|,\s*|', WP_ACCESSABLE_HOSTS);
     549
     550                return !in_array( $check['host'], $accessable_hosts ); //Inverse logic, If its in the array, then we can't access it.
    551551        }
    552552}
     
    607607                        if ( ($arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https') && extension_loaded('openssl') ) {
    608608                                $arrURL['host'] = 'ssl://' . $arrURL['host'];
    609                                 $arrURL['port'] = apply_filters('http_request_port', 443);
     609                                $arrURL['port'] = 443;
    610610                                $secure_transport = true;
    611611                        } else {
    612                                 $arrURL['port'] = apply_filters('http_request_default_port', 80);
     612                                $arrURL['port'] = 80;
    613613                        }
    614                 } else {
    615                         $arrURL['port'] = apply_filters('http_request_port', $arrURL['port'], $arrURL['host']);
    616614                }
    617615
     
    626624
    627625                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) {
    628                         if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
     626                        if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
    629627                                $handle = @fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] );
    630628                        else
    631629                                $handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] );
    632                 }
    633                 else {
    634                         if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
     630                } else {
     631                        if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
    635632                                $handle = fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] );
    636633                        else
     
    649646                        return new WP_Error('http_request_failed', $iError . ': ' . $strError);
    650647
    651                 // WordPress supports PHP 4.3, which has this function. Removed sanity checking for
    652                 // performance reasons.
    653648                stream_set_timeout($handle, $r['timeout'] );
    654649
    655                 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' );
    656                 $requestPath = empty($requestPath) ? '/' : $requestPath;
    657 
    658                 $strHeaders = '';
    659                 $strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";
    660 
    661                 if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
    662                         $strHeaders .= 'Host: ' . $arrURL['host'] .':'. $arrURL['port'] . "\r\n";
     650                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field.
     651                        $requestPath = $url;
     652                else
     653                        $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' );
     654
     655                if ( empty($requestPath) )
     656                        $requestPath .= '/';
     657
     658                $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";
     659
     660                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
     661                        $strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n";
    663662                else
    664663                        $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n";
    665664
    666                 if( isset($r['user-agent']) )
     665                if ( isset($r['user-agent']) )
    667666                        $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n";
    668667
     
    674673                }
    675674
    676                 if ( $proxy->use_authentication() ) {
     675                if ( $proxy->use_authentication() )
    677676                        $strHeaders .= $proxy->authentication_header() . "\r\n";
    678                 }
    679677
    680678                $strHeaders .= "\r\n";
     
    732730         * @return boolean False means this class can not be used, true means it can.
    733731         */
    734         function test($args = array()) {
     732        function test( $args = array() ) {
    735733                if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours
    736734                        return false;
    737735
    738                 if ( function_exists( 'fsockopen' ) && ( isset($args['ssl']) && !$args['ssl'] ) )
    739                         return apply_filters('use_fsockopen_transport', true);
    740 
    741                 return false;
     736                $is_ssl = isset($args['ssl']) && $args['ssl'];
     737
     738                if ( ! $is_ssl && function_exists( 'fsockopen' ) )
     739                        $use = true;
     740                elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) )
     741                        $use = true;
     742                else
     743                        $use = false;
     744
     745                return apply_filters('use_fsockopen_transport', $use, $args);
    742746        }
    743747}
     
    769773         *
    770774         * @param string $url URI resource.
    771          * @param str|array $args Optional. Override the defaults.
    772          * @return array 'headers', 'body', 'cookies' and 'response' keys.
    773          */
    774         function request($url, $args = array()) {
    775                 global $http_response_header;
    776 
    777                 $defaults = array(
    778                         'method' => 'GET', 'timeout' => 5,
    779                         'redirection' => 5, 'httpversion' => '1.0',
    780                         'blocking' => true,
    781                         'headers' => array(), 'body' => null, 'cookies' => array()
    782                 );
    783 
    784                 $r = wp_parse_args( $args, $defaults );
    785 
    786                 $arrURL = parse_url($url);
    787 
    788                 if ( false === $arrURL )
    789                         return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
    790 
    791                 if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
    792                         $url = str_replace($arrURL['scheme'], 'http', $url);
    793 
    794                 if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) )
    795                         $handle = @fopen($url, 'r');
    796                 else
    797                         $handle = fopen($url, 'r');
    798 
    799                 if (! $handle)
    800                         return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
    801 
    802                 // WordPress supports PHP 4.3, which has this function. Removed sanity
    803                 // checking for performance reasons.
    804                 stream_set_timeout($handle, $r['timeout'] );
    805 
    806                 if ( ! $r['blocking'] ) {
    807                         fclose($handle);
    808                         return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
    809                 }
    810 
    811                 $strResponse = '';
    812                 while ( ! feof($handle) )
    813                         $strResponse .= fread($handle, 4096);
    814 
    815                 $theHeaders = '';
    816                 if ( function_exists('stream_get_meta_data') ) {
    817                         $meta = stream_get_meta_data($handle);
    818                         $theHeaders = $meta['wrapper_data'];
    819                         if( isset( $meta['wrapper_data']['headers'] ) )
    820                                 $theHeaders = $meta['wrapper_data']['headers'];
    821                 } else {
    822                         if( ! isset( $http_response_header ) )
    823                                 global $http_response_header;
    824                         $theHeaders = $http_response_header;
    825                 }
    826 
    827                 fclose($handle);
    828 
    829                 $processedHeaders = WP_Http::processHeaders($theHeaders);
    830 
    831                 if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] )
    832                         $strResponse = WP_Http::chunkTransferDecode($strResponse);
    833 
    834                 if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($processedHeaders) )
    835                         $strResponse = WP_Http_Encoding::decompress( $strResponse );
    836 
    837                 return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response'], 'cookies' => $processedHeaders['cookies']);
    838         }
    839 
    840         /**
    841          * Whether this class can be used for retrieving an URL.
    842          *
    843          * @since 2.7.0
    844          * @static
    845          * @return boolean False means this class can not be used, true means it can.
    846          */
    847         function test() {
    848                 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
    849                         return false;
    850 
    851                         if (
    852                                 ( isset($args['ssl']) && !$args['ssl'] ) ||
    853                                 ( isset($args['local']) && $args['local'] == true && apply_filters('https_local_ssl_verify', true) != true ) ||
    854                                 ( isset($args['local']) && $args['local'] == false && apply_filters('https_ssl_verify', true) != true ) ||
    855                                 ( isset($args['sslverify']) && !$args['sslverify'] )
    856                         )
    857                                 return apply_filters('use_fopen_transport', true);
    858 
    859                 return false;
    860         }
    861 }
    862 
    863 /**
    864  * HTTP request method uses Streams to retrieve the url.
    865  *
    866  * Requires PHP 5.0+ and uses fopen with stream context. Requires that 'allow_url_fopen' PHP setting
    867  * to be enabled.
    868  *
    869  * Second preferred method for getting the URL, for PHP 5.
    870  *
    871  * @package WordPress
    872  * @subpackage HTTP
    873  * @since 2.7.0
    874  */
    875 class WP_Http_Streams {
    876         /**
    877          * Send a HTTP request to a URI using streams with fopen().
    878          *
    879          * @access public
    880          * @since 2.7.0
    881          *
    882          * @param string $url
    883775         * @param str|array $args Optional. Override the defaults.
    884776         * @return array 'headers', 'body', 'cookies' and 'response' keys.
     
    894786                $r = wp_parse_args( $args, $defaults );
    895787
     788                $arrURL = parse_url($url);
     789
     790                if ( false === $arrURL )
     791                        return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
     792
     793                if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
     794                        $url = str_replace($arrURL['scheme'], 'http', $url);
     795
     796                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) )
     797                        $handle = @fopen($url, 'r');
     798                else
     799                        $handle = fopen($url, 'r');
     800
     801                if (! $handle)
     802                        return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
     803
     804                stream_set_timeout($handle, $r['timeout'] );
     805
     806                if ( ! $r['blocking'] ) {
     807                        fclose($handle);
     808                        return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
     809                }
     810
     811                $strResponse = '';
     812                while ( ! feof($handle) )
     813                        $strResponse .= fread($handle, 4096);
     814
     815                if ( function_exists('stream_get_meta_data') ) {
     816                        $meta = stream_get_meta_data($handle);
     817                        $theHeaders = $meta['wrapper_data'];
     818                        if ( isset( $meta['wrapper_data']['headers'] ) )
     819                                $theHeaders = $meta['wrapper_data']['headers'];
     820                } else {
     821                        //$http_response_header is a PHP reserved variable which is set in the current-scope when using the HTTP Wrapper
     822                        //see http://php.oregonstate.edu/manual/en/reserved.variables.httpresponseheader.php
     823                        $theHeaders = $http_response_header;
     824                }
     825
     826                fclose($handle);
     827
     828                $processedHeaders = WP_Http::processHeaders($theHeaders);
     829
     830                if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] )
     831                        $strResponse = WP_Http::chunkTransferDecode($strResponse);
     832
     833                if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($processedHeaders) )
     834                        $strResponse = WP_Http_Encoding::decompress( $strResponse );
     835
     836                return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response'], 'cookies' => $processedHeaders['cookies']);
     837        }
     838
     839        /**
     840         * Whether this class can be used for retrieving an URL.
     841         *
     842         * @since 2.7.0
     843         * @static
     844         * @return boolean False means this class can not be used, true means it can.
     845         */
     846        function test($args = array()) {
     847                if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
     848                        return false;
     849
     850                $use = true;
     851
     852                //PHP does not verify SSL certs, We can only make a request via this transports if SSL Verification is turned off.
     853                $is_ssl = isset($args['ssl']) && $args['ssl'];
     854                if ( $is_ssl ) {
     855                        $is_local = isset($args['local']) && $args['local'];
     856                        $ssl_verify = isset($args['sslverify']) && $args['sslverify'];
     857                        if ( $is_local && true != apply_filters('https_local_ssl_verify', true) )
     858                                $use = true;
     859                        elseif ( !$is_local && true != apply_filters('https_ssl_verify', true) )
     860                                $use = true;
     861                        elseif ( !$ssl_verify )
     862                                $use = true;
     863                        else
     864                                $use = false;
     865                }
     866
     867                return apply_filters('use_fopen_transport', $use, $args);
     868        }
     869}
     870
     871/**
     872 * HTTP request method uses Streams to retrieve the url.
     873 *
     874 * Requires PHP 5.0+ and uses fopen with stream context. Requires that 'allow_url_fopen' PHP setting
     875 * to be enabled.
     876 *
     877 * Second preferred method for getting the URL, for PHP 5.
     878 *
     879 * @package WordPress
     880 * @subpackage HTTP
     881 * @since 2.7.0
     882 */
     883class WP_Http_Streams {
     884        /**
     885         * Send a HTTP request to a URI using streams with fopen().
     886         *
     887         * @access public
     888         * @since 2.7.0
     889         *
     890         * @param string $url
     891         * @param str|array $args Optional. Override the defaults.
     892         * @return array 'headers', 'body', 'cookies' and 'response' keys.
     893         */
     894        function request($url, $args = array()) {
     895                $defaults = array(
     896                        'method' => 'GET', 'timeout' => 5,
     897                        'redirection' => 5, 'httpversion' => '1.0',
     898                        'blocking' => true,
     899                        'headers' => array(), 'body' => null, 'cookies' => array()
     900                );
     901
     902                $r = wp_parse_args( $args, $defaults );
     903
    896904                if ( isset($r['headers']['User-Agent']) ) {
    897905                        $r['user-agent'] = $r['headers']['User-Agent'];
     
    911919
    912920                if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
    913                         $url = str_replace($arrURL['scheme'], 'http', $url);
     921                        $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url);
    914922
    915923                // Convert Header array to string.
    916924                $strHeaders = '';
    917925                if ( is_array( $r['headers'] ) )
    918                         foreach( $r['headers'] as $name => $value )
     926                        foreach ( $r['headers'] as $name => $value )
    919927                                $strHeaders .= "{$name}: $value\r\n";
    920928                else if ( is_string( $r['headers'] ) )
    921929                        $strHeaders = $r['headers'];
     930
     931                $is_local = isset($args['local']) && $args['local'];
     932                $ssl_verify = isset($args['sslverify']) && $args['sslverify'];
     933                if ( $is_local )
     934                        $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
     935                elseif ( ! $is_local )
     936                        $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
    922937
    923938                $arrContext = array('http' =>
     
    930945                                'timeout' => $r['timeout'],
    931946                                'ssl' => array(
    932                                                 'verify_peer' => apply_filters('https_ssl_verify', $r['sslverify']),
    933                                                 'verify_host' => apply_filters('https_ssl_verify', $r['sslverify'])
     947                                                'verify_peer' => $ssl_verify,
     948                                                'verify_host' => $ssl_verify
    934949                                )
    935950                        )
     
    939954
    940955                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
    941                         $arrContext['http']['proxy'] = 'tcp://'.$proxy->host().':'.$proxy->port();
     956                        $arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port();
     957                        $arrContext['http']['request_fulluri'] = true;
    942958
    943959                        // We only support Basic authentication so this will only work if that is what your proxy supports.
    944                         if ( $proxy->use_authentication() ) {
     960                        if ( $proxy->use_authentication() )
    945961                                $arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
    946                         }
    947962                }
    948963
     
    976991
    977992                $processedHeaders = array();
    978                 if( isset( $meta['wrapper_data']['headers'] ) )
     993                if ( isset( $meta['wrapper_data']['headers'] ) )
    979994                        $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']);
    980995                else
     
    10061021                        return false;
    10071022
    1008                 return apply_filters('use_streams_transport', true);
     1023                //HTTPS via Proxy was added in 5.1.0
     1024                $is_ssl = isset($args['ssl']) && $args['ssl'];
     1025                if ( $is_ssl && version_compare(PHP_VERSION, '5.1.0', '<') ) {
     1026                        $proxy = new WP_HTTP_Proxy();
     1027                        /**
     1028                         * No URL check, as its not currently passed to the ::test() function
     1029                         * In the case where a Proxy is in use, Just bypass this transport for HTTPS.
     1030                         */
     1031                        if ( $proxy->is_enabled() )
     1032                                return false;
     1033                }
     1034
     1035                return apply_filters('use_streams_transport', true, $args);
    10091036        }
    10101037}
     
    10701097
    10711098                if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] )
    1072                         $url = str_replace($arrURL['scheme'], 'http', $url);
     1099                        $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url);
     1100
     1101                $is_local = isset($args['local']) && $args['local'];
     1102                $ssl_verify = isset($args['sslverify']) && $args['sslverify'];
     1103                if ( $is_local )
     1104                        $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
     1105                elseif ( ! $is_local )
     1106                        $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
    10731107
    10741108                $options = array(
     
    10791113                        'headers' => $r['headers'],
    10801114                        'ssl' => array(
    1081                                 'verifypeer' => apply_filters('https_ssl_verify', $r['sslverify']),
    1082                                 'verifyhost' => apply_filters('https_ssl_verify', $r['sslverify'])
     1115                                'verifypeer' => $ssl_verify,
     1116                                'verifyhost' => $ssl_verify
    10831117                        )
    10841118                );
     
    11401174         */
    11411175        function test($args = array()) {
    1142                 if ( function_exists('http_request') )
    1143                         return apply_filters('use_http_extension_transport', true);
    1144 
    1145                 return false;
     1176                return apply_filters('use_http_extension_transport', function_exists('http_request'), $args );
    11461177        }
    11471178}
     
    12001231
    12011232                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
    1202                         curl_setopt( $handle, CURLOPT_HTTPPROXYTUNNEL, true );
    12031233
    12041234                        $isPHP5 = version_compare(PHP_VERSION, '5.0.0', '>=');
     
    12191249                        }
    12201250                }
     1251               
     1252                $is_local = isset($args['local']) && $args['local'];
     1253                $ssl_verify = isset($args['sslverify']) && $args['sslverify'];
     1254                if ( $is_local )
     1255                        $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
     1256                elseif ( ! $is_local )
     1257                        $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
    12211258
    12221259                curl_setopt( $handle, CURLOPT_URL, $url);
    12231260                curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
    1224                 curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, apply_filters('https_ssl_verify', $r['sslverify']) );
    1225                 curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, apply_filters('https_ssl_verify', $r['sslverify']) );
     1261                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify );
     1262                curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
    12261263                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    12271264                curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] );
     
    12511288                        // cURL expects full header strings in each element
    12521289                        $headers = array();
    1253                         foreach ( $r['headers'] as $name => $value ) {
     1290                        foreach ( $r['headers'] as $name => $value )
    12541291                                $headers[] = "{$name}: $value";
    1255                         }
    12561292                        curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers );
    12571293                }
     
    13181354        function test($args = array()) {
    13191355                if ( function_exists('curl_init') && function_exists('curl_exec') )
    1320                         return  apply_filters('use_curl_transport', true);
     1356                        return apply_filters('use_curl_transport', true, $args);
    13211357
    13221358                return false;
     
    13391375 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
    13401376 * You do not need to have localhost and the blog host in this list, because they will not be passed
    1341  * through the proxy.</li>
     1377 * through the proxy. The list should be presented in a comma separated list</li>
    13421378 * </ol>
    13431379 *
     
    13461382 * define('WP_PROXY_HOST', '192.168.84.101');
    13471383 * define('WP_PROXY_PORT', '8080');
    1348  * define('WP_PROXY_BYPASS_HOSTS', array('localhost', 'www.example.com'));
     1384 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
    13491385 * </code>
    13501386 *
     
    13541390class WP_HTTP_Proxy {
    13551391
    1356         function WP_HTTP_Proxy() {
    1357                 $this->__construct();
    1358         }
    1359 
    1360         function __construct() {
    1361 
    1362         }
    1363 
    13641392        /**
    13651393         * Whether proxy connection should be used.
     
    13721400         */
    13731401        function is_enabled() {
    1374                 return ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') );
     1402                return defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT');
    13751403        }
    13761404
     
    13851413         */
    13861414        function use_authentication() {
    1387                 return ( defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD') );
     1415                return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD');
    13881416        }
    13891417
     
    13961424         */
    13971425        function host() {
    1398                 if( defined('WP_PROXY_HOST') )
     1426                if ( defined('WP_PROXY_HOST') )
    13991427                        return WP_PROXY_HOST;
    14001428
     
    14101438         */
    14111439        function port() {
    1412                 if( defined('WP_PROXY_PORT') )
     1440                if ( defined('WP_PROXY_PORT') )
    14131441                        return WP_PROXY_PORT;
    14141442
     
    14241452         */
    14251453        function username() {
    1426                 if( defined('WP_PROXY_USERNAME') )
     1454                if ( defined('WP_PROXY_USERNAME') )
    14271455                        return WP_PROXY_USERNAME;
    14281456
     
    14381466         */
    14391467        function password() {
    1440                 if( defined('WP_PROXY_PASSWORD') )
     1468                if ( defined('WP_PROXY_PASSWORD') )
    14411469                        return WP_PROXY_PASSWORD;
    14421470
     
    14521480         */
    14531481        function authentication() {
    1454                 return $this->username() .':'. $this->password();
     1482                return $this->username() . ':' . $this->password();
    14551483        }
    14561484
     
    14631491         */
    14641492        function authentication_header() {
    1465                 return 'Proxy-Authentication: Basic '. base64_encode( $this->authentication() );
     1493                return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() );
    14661494        }
    14671495
     
    14851513
    14861514                // Malformed URL, can not process, but this could mean ssl, so let through anyway.
    1487                 if( $check === false )
     1515                if ( $check === false )
    14881516                        return true;
    14891517
    1490                 $home = parse_url( get_bloginfo('site_url') );
    1491 
    1492                 if ( $uri == 'localhost' || $uri == $home['host'] )
     1518                $home = parse_url( get_option('siteurl') );
     1519
     1520                if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] )
    14931521                        return false;
    14941522
    1495                 if ( defined('WP_PROXY_BYPASS_HOSTS') && is_array( WP_PROXY_BYPASS_HOSTS ) && in_array( $check['host'], WP_PROXY_BYPASS_HOSTS ) ) {
    1496                         return false;
    1497                 }
    1498 
    1499                 return true;
     1523                if ( !defined('WP_PROXY_BYPASS_HOSTS') )
     1524                        return true;
     1525               
     1526                static $bypass_hosts;
     1527                if ( null == $bypass_hosts )
     1528                        $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS);
     1529               
     1530                return !in_array( $check['host'], $bypass_hosts );
    15001531        }
    15011532}
    1502 
    1503 
    15041533/**
    15051534 * Internal representation of a single cookie.
     
    17451774                $decompressed = gzinflate( $compressed );
    17461775
    1747                 if( false !== $decompressed )
     1776                if ( false !== $decompressed )
    17481777                        return $decompressed;
    17491778
    17501779                $decompressed = gzuncompress( $compressed );
    17511780
    1752                 if( false !== $decompressed )
     1781                if ( false !== $decompressed )
    17531782                        return $decompressed;
    17541783
    17551784                $decompressed = gzdecode( $compressed );
    17561785
    1757                 if( false !== $decompressed )
     1786                if ( false !== $decompressed )
    17581787                        return $decompressed;
    17591788
     
    17701799        function accept_encoding() {
    17711800                $type = array();
    1772                 if( function_exists( 'gzinflate' ) )
     1801                if ( function_exists( 'gzinflate' ) )
    17731802                        $type[] = 'deflate;q=1.0';
    17741803
    1775                 if( function_exists( 'gzuncompress' ) )
     1804                if ( function_exists( 'gzuncompress' ) )
    17761805                        $type[] = 'compress;q=0.5';
    17771806
    1778                 if( function_exists( 'gzdecode' ) )
     1807                if ( function_exists( 'gzdecode' ) )
    17791808                        $type[] = 'gzip;q=0.5';
    17801809
     
    18021831         */
    18031832        function should_decode($headers) {
    1804                 if( is_array( $headers ) ) {
    1805                         if( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
     1833                if ( is_array( $headers ) ) {
     1834                        if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
    18061835                                return true;
    18071836                } else if( is_string( $headers ) ) {
     
    18241853         */
    18251854        function is_available() {
    1826                 return ( function_exists('gzuncompress') || function_exists('gzdeflate') ||
    1827                                  function_exists('gzinflate') );
     1855                return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') );
    18281856        }
    18291857}
     
    18911919function wp_remote_get($url, $args = array()) {
    18921920        $objFetchSite = _wp_http_get_object();
    1893 
    18941921        return $objFetchSite->get($url, $args);
    18951922}
Note: See TracChangeset for help on using the changeset viewer.