WordPress.org

Make WordPress Core

Ticket #4011: 4011.3.diff

File 4011.3.diff, 30.9 KB (added by jacobsantos, 6 years ago)

Update patch for current trunk

  • http.php

     
    1313 */ 
    1414 
    1515/** 
    16  * Implementation for deflate and gzip transfer encodings. 
    17  * 
    18  * Includes RFC 1950, RFC 1951, and RFC 1952. 
    19  * 
    20  * @since unknown 
    21  * @package WordPress 
    22  * @subpackage HTTP 
    23  */ 
    24 class WP_Http_Encoding { 
    25  
    26         /** 
    27          * Compress raw string using the deflate format. 
    28          * 
    29          * Supports the RFC 1951 standard. 
    30          * 
    31          * @since unknown 
    32          * 
    33          * @param string $raw String to compress. 
    34          * @param int $level Optional, default is 9. Compression level, 9 is highest. 
    35          * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports. 
    36          * @return string|bool False on failure. 
    37          */ 
    38         function compress( $raw, $level = 9, $supports = null ) { 
    39                 return gzdeflate( $raw, $level ); 
    40         } 
    41  
    42         /** 
    43          * Decompression of deflated string. 
    44          * 
    45          * Will attempt to decompress using the RFC 1950 standard, and if that fails 
    46          * then the RFC 1951 standard deflate will be attempted. Finally, the RFC 
    47          * 1952 standard gzip decode will be attempted. If all fail, then the 
    48          * original compressed string will be returned. 
    49          * 
    50          * @since unknown 
    51          * 
    52          * @param string $compressed String to decompress. 
    53          * @param int $length The optional length of the compressed data. 
    54          * @return string|bool False on failure. 
    55          */ 
    56         function decompress( $compressed, $length = null ) { 
    57                 $decompressed = gzinflate( $compressed ); 
    58  
    59                 if( false !== $decompressed ) 
    60                         return $decompressed; 
    61  
    62                 $decompressed = gzuncompress( $compressed ); 
    63  
    64                 if( false !== $decompressed ) 
    65                         return $decompressed; 
    66  
    67                 $decompressed = gzdecode( $compressed ); 
    68  
    69                 if( false !== $decompressed ) 
    70                         return $decompressed; 
    71  
    72                 return $compressed; 
    73         } 
    74  
    75         /** 
    76          * What encoding types to accept and their priority values. 
    77          * 
    78          * @since unknown 
    79          * 
    80          * @return string Types of encoding to accept. 
    81          */ 
    82         function accept_encoding() { 
    83                 $type = array(); 
    84                 if( function_exists( 'gzinflate' ) ) 
    85                         $type[] = 'deflate;q=1.0'; 
    86  
    87                 if( function_exists( 'gzuncompress' ) ) 
    88                         $type[] = 'compress;q=0.5'; 
    89  
    90                 if( function_exists( 'gzdecode' ) ) 
    91                         $type[] = 'gzip;q=0.5'; 
    92  
    93                 return implode(', ', $type); 
    94         } 
    95  
    96         /** 
    97          * What enconding the content used when it was compressed to send in the headers. 
    98          * 
    99          * @since unknown 
    100          * 
    101          * @return string Content-Encoding string to send in the header. 
    102          */ 
    103         function content_encoding() { 
    104                 return 'deflate'; 
    105         } 
    106  
    107         /** 
    108          * Whether the content be decoded based on the headers. 
    109          * 
    110          * @since unknown 
    111          * 
    112          * @param array|string $headers All of the available headers. 
    113          * @return bool 
    114          */ 
    115         function should_decode($headers) { 
    116                 if( is_array( $headers ) ) { 
    117                         if( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) 
    118                                 return true; 
    119                 } else if( is_string( $headers ) ) { 
    120                         return ( stripos($headers, 'content-encoding:') !== false ); 
    121                 } 
    122  
    123                 return false; 
    124         } 
    125  
    126         /** 
    127          * Whether decompression and compression are supported by the PHP version. 
    128          * 
    129          * Each function is tested instead of checking for the zlib extension, to 
    130          * ensure that the functions all exist in the PHP version and aren't 
    131          * disabled. 
    132          * 
    133          * @since unknown 
    134          * 
    135          * @return bool 
    136          */ 
    137         function is_available() { 
    138                 return ( function_exists('gzuncompress') || function_exists('gzdeflate') || 
    139                                  function_exists('gzinflate') ); 
    140         } 
    141 } 
    142  
    143 /** 
    14416 * WordPress HTTP Class for managing HTTP Transports and making HTTP requests. 
    14517 * 
    146  * This class is called for the functionality of making HTTP requests and should 
    147  * replace Snoopy functionality, eventually. There is no available functionality 
    148  * to add HTTP transport implementations, since most of the HTTP transports are 
    149  * added and available for use. 
     18 * This class is called for the functionality of making HTTP requests and should replace Snoopy 
     19 * functionality, eventually. There is no available functionality to add HTTP transport 
     20 * implementations, since most of the HTTP transports are added and available for use. 
    15021 * 
    151  * The exception is that cURL is not available as a transport and lacking an 
    152  * implementation. It will be added later and should be a patch on the WordPress 
    153  * Trac. 
     22 * The exception is that cURL is not available as a transport and lacking an implementation. It will 
     23 * be added later and should be a patch on the WordPress Trac. 
    15424 * 
    155  * There are no properties, because none are needed and for performance reasons. 
    156  * Some of the functions are static and while they do have some overhead over 
    157  * functions in PHP4, the purpose is maintainability. When PHP5 is finally the 
    158  * requirement, it will be easy to add the static keyword to the code. It is not 
    159  * as easy to convert a function to a method after enough code uses the old way. 
     25 * There are no properties, because none are needed and for performance reasons. Some of the 
     26 * functions are static and while they do have some overhead over functions in PHP4, the purpose is 
     27 * maintainability. When PHP5 is finally the requirement, it will be easy to add the static keyword 
     28 * to the code. It is not as easy to convert a function to a method after enough code uses the old 
     29 * way. 
    16030 * 
    161  * Debugging includes several actions, which pass different variables for 
    162  * debugging the HTTP API. 
     31 * Debugging includes several actions, which pass different variables for debugging the HTTP API. 
    16332 * 
    164  * <strong>http_transport_get_debug</strong> - gives working, nonblocking, and 
    165  * blocking transports. 
     33 * <strong>http_transport_get_debug</strong> - gives working, nonblocking, and blocking transports. 
    16634 * 
    167  * <strong>http_transport_post_debug</strong> - gives working, nonblocking, and 
    168  * blocking transports. 
     35 * <strong>http_transport_post_debug</strong> - gives working, nonblocking, and blocking transports. 
    16936 * 
    17037 * @package WordPress 
    17138 * @subpackage HTTP 
     
    311178        /** 
    312179         * Send a HTTP request to a URI. 
    313180         * 
    314          * The body and headers are part of the arguments. The 'body' argument is 
    315          * for the body and will accept either a string or an array. The 'headers' 
    316          * argument should be an array, but a string is acceptable. If the 'body' 
    317          * argument is an array, then it will automatically be escaped using 
    318          * http_build_query(). 
     181         * The body and headers are part of the arguments. The 'body' argument is for the body and will 
     182         * accept either a string or an array. The 'headers' argument should be an array, but a string 
     183         * is acceptable. If the 'body' argument is an array, then it will automatically be escaped 
     184         * using http_build_query(). 
    319185         * 
    320          * The only URI that are supported in the HTTP Transport implementation are 
    321          * the HTTP and HTTPS protocols. HTTP and HTTPS are assumed so the server 
    322          * might not know how to handle the send headers. Other protocols are 
    323          * unsupported and most likely will fail. 
     186         * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS 
     187         * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send 
     188         * headers. Other protocols are unsupported and most likely will fail. 
    324189         * 
    325          * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 
    326          * 'blocking' and 'user-agent'. 
     190         * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and 
     191         * 'user-agent'. 
    327192         * 
    328          * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports 
    329          * technically allow others, but should not be assumed. The 'timeout' is 
    330          * used to sent how long the connection should stay open before failing when 
    331          * no response. 'redirection' is used to track how many redirects were taken 
    332          * and used to sent the amount for other transports, but not all transports 
     193         * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow 
     194         * others, but should not be assumed. The 'timeout' is used to sent how long the connection 
     195         * should stay open before failing when no response. 'redirection' is used to track how many 
     196         * redirects were taken and used to sent the amount for other transports, but not all transports 
    333197         * accept setting that value. 
    334198         * 
    335          * The 'httpversion' option is used to sent the HTTP version and accepted 
    336          * values are '1.0', and '1.1' and should be a string. Version 1.1 is not 
    337          * supported, because of chunk response. The 'user-agent' option is the 
    338          * user-agent and is used to replace the default user-agent, which is 
     199         * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and 
     200         * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The 
     201         * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is 
    339202         * 'WordPress/WP_Version', where WP_Version is the value from $wp_version. 
    340203         * 
    341          * 'blocking' is the default, which is used to tell the transport, whether 
    342          * it should halt PHP while it performs the request or continue regardless. 
    343          * Actually, that isn't entirely correct. Blocking mode really just means 
    344          * whether the fread should just pull what it can whenever it gets bytes or 
    345          * if it should wait until it has enough in the buffer to read or finishes 
    346          * reading the entire content. It doesn't actually always mean that PHP will 
    347          * continue going after making the request. 
     204         * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP 
     205         * while it performs the request or continue regardless. Actually, that isn't entirely correct. 
     206         * Blocking mode really just means whether the fread should just pull what it can whenever it 
     207         * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading 
     208         * the entire content. It doesn't actually always mean that PHP will continue going after making 
     209         * the request. 
    348210         * 
    349211         * @access public 
    350212         * @since 2.7.0 
     
    569431 
    570432                return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies); 
    571433        } 
    572          
     434 
    573435        /** 
    574436         * Takes the arguments for a ::request() and checks for the cookie array. 
    575437         * 
     
    597459        /** 
    598460         * Decodes chunk transfer-encoding, based off the HTTP 1.1 specification. 
    599461         * 
    600          * Based off the HTTP http_encoding_dechunk function. Does not support 
    601          * UTF-8. Does not support returning footer headers. Shouldn't be too 
    602          * difficult to support it though. 
     462         * Based off the HTTP http_encoding_dechunk function. Does not support UTF-8. Does not support 
     463         * returning footer headers. Shouldn't be too difficult to support it though. 
    603464         * 
    604465         * @todo Add support for footer chunked headers. 
    605466         * @access public 
     
    651512         * and this will only allow localhost and your blog to make requests. The constant 
    652513         * WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests. 
    653514         * 
    654          * @since unknown 
     515         * @since 2.8.0 
    655516         * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests. 
    656517         * 
    657518         * @param string $uri URI of url. 
     
    693554/** 
    694555 * HTTP request method uses fsockopen function to retrieve the url. 
    695556 * 
    696  * This would be the preferred method, but the fsockopen implementation has the 
    697  * most overhead of all the HTTP transport implementations. 
     557 * This would be the preferred method, but the fsockopen implementation has the most overhead of all 
     558 * the HTTP transport implementations. 
    698559 * 
    699560 * @package WordPress 
    700561 * @subpackage HTTP 
     
    751612                                $arrURL['port'] = apply_filters('http_request_default_port', 80); 
    752613                        } 
    753614                } else { 
    754                         $arrURL['port'] = apply_filters('http_request_port', $arrURL['port']); 
     615                        $arrURL['port'] = apply_filters('http_request_port', $arrURL['port'], $arrURL['host']); 
    755616                } 
    756617 
    757                 // There are issues with the HTTPS and SSL protocols that cause errors 
    758                 // that can be safely ignored and should be ignored. 
     618                // There are issues with the HTTPS and SSL protocols that cause errors that can be safely 
     619                // ignored and should be ignored. 
    759620                if ( true === $secure_transport ) 
    760621                        $error_reporting = error_reporting(0); 
    761622 
    762623                $startDelay = time(); 
    763624 
    764                 if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) 
    765                         $handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); 
    766                 else 
    767                         $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); 
     625                $proxy = new WP_HTTP_Proxy(); 
    768626 
     627                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) { 
     628                        if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 
     629                                $handle = @fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] ); 
     630                        else 
     631                                $handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); 
     632                } 
     633                else { 
     634                        if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 
     635                                $handle = fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] ); 
     636                        else 
     637                                $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); 
     638                } 
     639 
    769640                $endDelay = time(); 
    770641 
    771                 // If the delay is greater than the timeout then fsockopen should't be 
    772                 // used, because it will cause a long delay. 
     642                // If the delay is greater than the timeout then fsockopen should't be used, because it will 
     643                // cause a long delay. 
    773644                $elapseDelay = ($endDelay-$startDelay) > $r['timeout']; 
    774645                if ( true === $elapseDelay ) 
    775646                        add_option( 'disable_fsockopen', $endDelay, null, true ); 
     
    777648                if ( false === $handle ) 
    778649                        return new WP_Error('http_request_failed', $iError . ': ' . $strError); 
    779650 
    780                 // WordPress supports PHP 4.3, which has this function. Removed sanity 
    781                 // checking for performance reasons. 
     651                // WordPress supports PHP 4.3, which has this function. Removed sanity checking for 
     652                // performance reasons. 
    782653                stream_set_timeout($handle, $r['timeout'] ); 
    783654 
    784655                $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); 
     
    786657 
    787658                $strHeaders = ''; 
    788659                $strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; 
    789                 $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; 
    790660 
     661                if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 
     662                        $strHeaders .= 'Host: ' . $arrURL['host'] .':'. $arrURL['port'] . "\r\n"; 
     663                else 
     664                        $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; 
     665 
    791666                if( isset($r['user-agent']) ) 
    792667                        $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; 
    793668 
     
    798673                        $strHeaders .= $r['headers']; 
    799674                } 
    800675 
     676                if ( $proxy->use_authentication() ) { 
     677                        $strHeaders .= $proxy->authentication_header() . "\r\n"; 
     678                } 
     679 
    801680                $strHeaders .= "\r\n"; 
    802681 
    803682                if ( ! is_null($r['body']) ) 
     
    866745/** 
    867746 * HTTP request method uses fopen function to retrieve the url. 
    868747 * 
    869  * Requires PHP version greater than 4.3.0 for stream support. Does not allow 
    870  * for $context support, but should still be okay, to write the headers, before 
    871  * getting the response. Also requires that 'allow_url_fopen' to be enabled. 
     748 * Requires PHP version greater than 4.3.0 for stream support. Does not allow for $context support, 
     749 * but should still be okay, to write the headers, before getting the response. Also requires that 
     750 * 'allow_url_fopen' to be enabled. 
    872751 * 
    873752 * @package WordPress 
    874753 * @subpackage HTTP 
     
    878757        /** 
    879758         * Send a HTTP request to a URI using fopen(). 
    880759         * 
    881          * This transport does not support sending of headers and body, therefore 
    882          * should not be used in the instances, where there is a body and headers. 
     760         * This transport does not support sending of headers and body, therefore should not be used in 
     761         * the instances, where there is a body and headers. 
    883762         * 
    884763         * Notes: Does not support non-blocking mode. Ignores 'redirection' option. 
    885764         * 
     
    984863/** 
    985864 * HTTP request method uses Streams to retrieve the url. 
    986865 * 
    987  * Requires PHP 5.0+ and uses fopen with stream context. Requires that 
    988  * 'allow_url_fopen' PHP setting to be enabled. 
     866 * Requires PHP 5.0+ and uses fopen with stream context. Requires that 'allow_url_fopen' PHP setting 
     867 * to be enabled. 
    989868 * 
    990869 * Second preferred method for getting the URL, for PHP 5. 
    991870 * 
     
    1056935                        ) 
    1057936                ); 
    1058937 
     938                $proxy = new WP_HTTP_Proxy(); 
     939 
     940                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 
     941                        // WTF happens when the user stupidly puts http:// in the host? Bad things. Really, 
     942                        // really bad things happen. Not exactly unleashing demons from hell, but you know. 
     943                        // Just as bad probably. Actually, none of the other transports should work in that case 
     944                        // so no sanitization is done. If there is, it should be done in the 
     945                        // WP_HTTP_Proxy::host(). 
     946                        // 
     947                        // On second thought, why is it tcp protocol? Why not http? What if the proxy is http 
     948                        // and not tcp? Even though, technically, http is tcp, but just a specialized form of 
     949                        // tcp. Behavior is undefined, so it is probably good that not a lot of users will be 
     950                        // affected by FUBAR behavior. 
     951                        // 
     952                        // Is it another WTF? that this multiline comment isn't using multiline comment syntax? 
     953                        $arrContext['http']['proxy'] = 'tcp://'.$proxy->host().':'.$proxy->port(); 
     954 
     955                        // Yeah, this may or may not work. Good luck. 
     956                        if ( $proxy->use_authentication() ) { 
     957                                $arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n"; 
     958                        } 
     959                } 
     960 
    1059961                if ( ! is_null($r['body']) && ! empty($r['body'] ) ) 
    1060962                        $arrContext['http']['content'] = $r['body']; 
    1061963 
     
    1069971                if ( ! $handle) 
    1070972                        return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); 
    1071973 
    1072                 // WordPress supports PHP 4.3, which has this function. Removed sanity 
    1073                 // checking for performance reasons. 
     974                // WordPress supports PHP 4.3, which has this function. Removed sanity checking for 
     975                // performance reasons. 
    1074976                stream_set_timeout($handle, $r['timeout'] ); 
    1075977 
    1076978                if ( ! $r['blocking'] ) { 
     
    11221024/** 
    11231025 * HTTP request method uses HTTP extension to retrieve the url. 
    11241026 * 
    1125  * Requires the HTTP extension to be installed. This would be the preferred 
    1126  * transport since it can handle a lot of the problems that forces the others to 
    1127  * use the HTTP version 1.0. Even if PHP 5.2+ is being used, it doesn't mean 
    1128  * that the HTTP extension will be enabled. 
     1027 * Requires the HTTP extension to be installed. This would be the preferred transport since it can 
     1028 * handle a lot of the problems that forces the others to use the HTTP version 1.0. Even if PHP 5.2+ 
     1029 * is being used, it doesn't mean that the HTTP extension will be enabled. 
    11291030 * 
    11301031 * @package WordPress 
    11311032 * @subpackage HTTP 
     
    11611062                        $r['user-agent'] = $r['headers']['user-agent']; 
    11621063                        unset($r['headers']['user-agent']); 
    11631064                } 
    1164                  
     1065 
    11651066                // Construct Cookie: header if any cookies are set 
    11661067                WP_Http::buildCookieHeader( $r ); 
    11671068 
     
    11941095                        ) 
    11951096                ); 
    11961097 
     1098                // The HTTP extensions offers really easy proxy support. 
     1099                $proxy = new WP_HTTP_Proxy(); 
     1100 
     1101                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 
     1102                        $options['proxyhost'] = $proxy->host(); 
     1103                        $options['proxyport'] = $proxy->port(); 
     1104                        $options['proxytype'] = HTTP_PROXY_HTTP; 
     1105 
     1106                        if ( $proxy->use_authentication() ) { 
     1107                                $options['proxyauth'] = $proxy->authentication(); 
     1108                                $options['proxyauthtype'] = HTTP_AUTH_BASIC; 
     1109                        } 
     1110                } 
     1111 
    11971112                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) //Emits warning level notices for max redirects and timeouts 
    11981113                        $strResponse = @http_request($r['method'], $url, $r['body'], $options, $info); 
    11991114                else 
     
    12821197                        unset($r['headers']['user-agent']); 
    12831198                } 
    12841199 
    1285                 // Construct Cookie: header if any cookies are set 
     1200                // Construct Cookie: header if any cookies are set. 
    12861201                WP_Http::buildCookieHeader( $r ); 
    12871202 
    1288                 // cURL extension will sometimes fail when the timeout is less than 1 as 
    1289                 // it may round down to 0, which gives it unlimited timeout. 
     1203                // cURL extension will sometimes fail when the timeout is less than 1 as it may round down 
     1204                // to 0, which gives it unlimited timeout. 
    12901205                if ( $r['timeout'] > 0 && $r['timeout'] < 1 ) 
    12911206                        $r['timeout'] = 1; 
    12921207 
    12931208                $handle = curl_init(); 
    12941209 
     1210                // cURL offers really easy proxy support. 
     1211                $proxy = new WP_HTTP_Proxy(); 
     1212 
     1213                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 
     1214                        curl_setopt( $handle, CURLOPT_HTTPPROXYTUNNEL, true ); 
     1215 
     1216                        $isPHP5 = version_compare(PHP_VERSION, '5.0.0', '>='); 
     1217 
     1218                        if ( $isPHP5 ) { 
     1219                                curl_setopt( $handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP ); 
     1220                                curl_setopt( $handle, CURLOPT_PROXY, $proxy->host() ); 
     1221                                curl_setopt( $handle, CURLOPT_PROXYPORT, $proxy->port() ); 
     1222                        } else { 
     1223                                curl_setopt( $handle, CURLOPT_PROXY, $proxy->host() .':'. $proxy->port() ); 
     1224                        } 
     1225 
     1226                        if ( $proxy->use_authentication() ) { 
     1227                                if ( $isPHP5 ) 
     1228                                        curl_setopt( $handle, CURLOPT_PROXYAUTH, CURLAUTH_BASIC ); 
     1229 
     1230                                curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() ); 
     1231                        } 
     1232                } 
     1233 
    12951234                curl_setopt( $handle, CURLOPT_URL, $url); 
    12961235                curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); 
    12971236                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, apply_filters('https_ssl_verify', $r['sslverify']) ); 
     
    13341273                else 
    13351274                        curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); 
    13361275 
    1337                 // Cookies are not handled by the HTTP API currently. Allow for plugin 
    1338                 // authors to handle it themselves... Although, it is somewhat pointless 
    1339                 // without some reference. 
     1276                // Cookies are not handled by the HTTP API currently. Allow for plugin authors to handle it 
     1277                // themselves... Although, it is somewhat pointless without some reference. 
    13401278                do_action_ref_array( 'http_api_curl', array(&$handle) ); 
    13411279 
    1342                 // We don't need to return the body, so don't. Just execute request 
    1343                 // and return. 
     1280                // We don't need to return the body, so don't. Just execute request and return. 
    13441281                if ( ! $r['blocking'] ) { 
    13451282                        curl_exec( $handle ); 
    13461283                        curl_close( $handle ); 
     
    13501287                $theResponse = curl_exec( $handle ); 
    13511288 
    13521289                if ( !empty($theResponse) ) { 
     1290                        $parts = explode("\r\n\r\n", $theResponse); 
     1291                         
    13531292                        $headerLength = curl_getinfo($handle, CURLINFO_HEADER_SIZE); 
    13541293                        $theHeaders = trim( substr($theResponse, 0, $headerLength) ); 
    13551294                        $theBody = substr( $theResponse, $headerLength ); 
     
    13891328         * @return boolean False means this class can not be used, true means it can. 
    13901329         */ 
    13911330        function test($args = array()) { 
    1392                 if ( function_exists('curl_init') && function_exists('curl_exec') ) 
     1331                if ( function_exists('curl_init') && function_exists('curl_exec') && apply_filters('use_curl_transport', true) ) 
    13931332                        return  apply_filters('use_curl_transport', true); 
    13941333 
    13951334                return false; 
    13961335        } 
    13971336} 
    13981337 
     1338/** 
     1339 * Adds Proxy support to the WordPress HTTP API. 
     1340 * 
     1341 * Proxy support is fringe enough that it isn't support in WordPress by default, meaning no plans 
     1342 * were made to implement it. Most WordPress users are not going to benefit with its support, but 
     1343 * enough people have made a stink out of the lack of it that it should be supported. 
     1344 * 
     1345 * There are caveats to proxy support. It requires that defines be made in the wp-config.php file to 
     1346 * enable proxy support. There are also a few filters that plugins can hook into for some of the 
     1347 * constants. 
     1348 * 
     1349 * The constants are as follows: 
     1350 * <ol> 
     1351 * <li>WP_PROXY_HOST - Enable proxy support and host for connecting.</li> 
     1352 * <li>WP_PROXY_PORT - Proxy port for connection. No default, must be defined.</li> 
     1353 * <li>WP_PROXY_USERNAME - Proxy username, if it requires authentication.</li> 
     1354 * <li>WP_PROXY_PASSWORD - Proxy password, if it requires authentication.</li> 
     1355 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy. 
     1356 * You do not need to have localhost and the blog host in this list, because they will not be passed 
     1357 * through the proxy.</li> 
     1358 * </ol> 
     1359 * 
     1360 * An example can be as seen below. 
     1361 * <code> 
     1362 * define('WP_PROXY_HOST', '192.168.84.101'); 
     1363 * define('WP_PROXY_PORT', '8080'); 
     1364 * define('WP_PROXY_BYPASS_HOSTS', array('localhost', 'www.example.com')); 
     1365 * </code> 
     1366 * 
     1367 * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress. 
     1368 * @since unknown 
     1369 */ 
     1370class WP_HTTP_Proxy { 
    13991371 
     1372        function WP_HTTP_Proxy() { 
     1373                $this->__construct(); 
     1374        } 
     1375 
     1376        function __construct() { 
     1377                 
     1378        } 
     1379 
     1380        /** 
     1381         * Whether proxy connection should be used. 
     1382         * 
     1383         * @since unknown 
     1384         * @use WP_PROXY_HOST 
     1385         * @use WP_PROXY_PORT 
     1386         * 
     1387         * @return bool 
     1388         */ 
     1389        function is_enabled() { 
     1390                return ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') ); 
     1391        } 
     1392 
     1393        /** 
     1394         * Whether authentication should be used. 
     1395         * 
     1396         * @since unknown 
     1397         * @use WP_PROXY_USERNAME 
     1398         * @use WP_PROXY_PASSWORD 
     1399         * 
     1400         * @return bool 
     1401         */ 
     1402        function use_authentication() { 
     1403                return ( defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD') ); 
     1404        } 
     1405 
     1406        /** 
     1407         * Retrieve the host for the proxy server. 
     1408         * 
     1409         * @since unknown 
     1410         * 
     1411         * @return string 
     1412         */ 
     1413        function host() { 
     1414                if( defined('WP_PROXY_HOST') ) 
     1415                        return WP_PROXY_HOST; 
     1416 
     1417                return ''; 
     1418        } 
     1419 
     1420        /** 
     1421         * Retrieve the port for the proxy server. 
     1422         * 
     1423         * @since unknown 
     1424         * 
     1425         * @return string 
     1426         */ 
     1427        function port() { 
     1428                if( defined('WP_PROXY_PORT') ) 
     1429                        return WP_PROXY_PORT; 
     1430 
     1431                return ''; 
     1432        } 
     1433 
     1434        /** 
     1435         * Retrieve the username for proxy authentication. 
     1436         * 
     1437         * @since unknown 
     1438         * 
     1439         * @return string 
     1440         */ 
     1441        function username() { 
     1442                if( defined('WP_PROXY_USERNAME') ) 
     1443                        return WP_PROXY_USERNAME; 
     1444 
     1445                return ''; 
     1446        } 
     1447 
     1448        /** 
     1449         * Retrieve the password for proxy authentication. 
     1450         * 
     1451         * @since unknown 
     1452         * 
     1453         * @return string 
     1454         */ 
     1455        function password() { 
     1456                if( defined('WP_PROXY_PASSWORD') ) 
     1457                        return WP_PROXY_PASSWORD; 
     1458 
     1459                return ''; 
     1460        } 
     1461 
     1462        /** 
     1463         * Retrieve authentication string for proxy authentication. 
     1464         * 
     1465         * @since unknown 
     1466         * 
     1467         * @return string 
     1468         */ 
     1469        function authentication() { 
     1470                return $this->username() .':'. $this->password(); 
     1471        } 
     1472 
     1473        /** 
     1474         * Retrieve header string for proxy authentication. 
     1475         * 
     1476         * @since unknown 
     1477         * 
     1478         * @return string 
     1479         */ 
     1480        function authentication_header() { 
     1481                return 'Proxy-Authentication: Basic '. base64_encode( $this->authentication() ); 
     1482        } 
     1483 
     1484        /** 
     1485         * Whether URL should be sent through the proxy server. 
     1486         * 
     1487         * We want to keep localhost and the blog URL from being sent through the proxy server, because 
     1488         * some proxies can not handle this. We also have the constant available for defining other 
     1489         * hosts that won't be sent through the proxy. 
     1490         * 
     1491         * @uses WP_PROXY_BYPASS_HOSTS 
     1492         * @since unknown 
     1493         * 
     1494         * @param string $uri URI to check. 
     1495         * @return bool True, to send through the proxy and false if, the proxy should not be used. 
     1496         */ 
     1497        function send_through_proxy( $uri ) { 
     1498                // parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. 
     1499                // This will be displayed on blogs, which is not reasonable. 
     1500                $check = @parse_url($uri); 
     1501 
     1502                // Malformed URL, can not process, but this could mean ssl, so let through anyway. 
     1503                if( $check === false ) 
     1504                        return true; 
     1505 
     1506                $home = parse_url( get_bloginfo('site_url') ); 
     1507 
     1508                if ( $uri == 'localhost' || $uri == $home['host'] ) 
     1509                        return false; 
     1510 
     1511                if ( defined('WP_PROXY_BYPASS_HOSTS') && is_array( WP_PROXY_BYPASS_HOSTS ) && in_array( $check['host'], WP_PROXY_BYPASS_HOSTS ) ) { 
     1512                                return false; 
     1513                } 
     1514 
     1515                return true; 
     1516        } 
     1517} 
     1518 
     1519 
    14001520/** 
    14011521 * Internal representation of a single cookie. 
    14021522 * 
    1403  * Returned cookies are represented using this class, and when cookies are 
    1404  * set, if they are not already a WP_Http_Cookie() object, then they are turned 
    1405  * into one. 
     1523 * Returned cookies are represented using this class, and when cookies are set, if they are not 
     1524 * already a WP_Http_Cookie() object, then they are turned into one. 
    14061525 * 
    14071526 * @todo The WordPress convention is to use underscores instead of camelCase for function and method 
    14081527 * names. Need to switch to use underscores instead for the methods. 
     
    15981717} 
    15991718 
    16001719/** 
     1720 * Implementation for deflate and gzip transfer encodings. 
     1721 * 
     1722 * Includes RFC 1950, RFC 1951, and RFC 1952. 
     1723 * 
     1724 * @since 2.8 
     1725 * @package WordPress 
     1726 * @subpackage HTTP 
     1727 */ 
     1728class WP_Http_Encoding { 
     1729 
     1730        /** 
     1731         * Compress raw string using the deflate format. 
     1732         * 
     1733         * Supports the RFC 1951 standard. 
     1734         * 
     1735         * @since 2.8 
     1736         * 
     1737         * @param string $raw String to compress. 
     1738         * @param int $level Optional, default is 9. Compression level, 9 is highest. 
     1739         * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports. 
     1740         * @return string|bool False on failure. 
     1741         */ 
     1742        function compress( $raw, $level = 9, $supports = null ) { 
     1743                return gzdeflate( $raw, $level ); 
     1744        } 
     1745 
     1746        /** 
     1747         * Decompression of deflated string. 
     1748         * 
     1749         * Will attempt to decompress using the RFC 1950 standard, and if that fails 
     1750         * then the RFC 1951 standard deflate will be attempted. Finally, the RFC 
     1751         * 1952 standard gzip decode will be attempted. If all fail, then the 
     1752         * original compressed string will be returned. 
     1753         * 
     1754         * @since 2.8 
     1755         * 
     1756         * @param string $compressed String to decompress. 
     1757         * @param int $length The optional length of the compressed data. 
     1758         * @return string|bool False on failure. 
     1759         */ 
     1760        function decompress( $compressed, $length = null ) { 
     1761                $decompressed = gzinflate( $compressed ); 
     1762 
     1763                if( false !== $decompressed ) 
     1764                        return $decompressed; 
     1765 
     1766                $decompressed = gzuncompress( $compressed ); 
     1767 
     1768                if( false !== $decompressed ) 
     1769                        return $decompressed; 
     1770 
     1771                $decompressed = gzdecode( $compressed ); 
     1772 
     1773                if( false !== $decompressed ) 
     1774                        return $decompressed; 
     1775 
     1776                return $compressed; 
     1777        } 
     1778 
     1779        /** 
     1780         * What encoding types to accept and their priority values. 
     1781         * 
     1782         * @since 2.8 
     1783         * 
     1784         * @return string Types of encoding to accept. 
     1785         */ 
     1786        function accept_encoding() { 
     1787                $type = array(); 
     1788                if( function_exists( 'gzinflate' ) ) 
     1789                        $type[] = 'deflate;q=1.0'; 
     1790 
     1791                if( function_exists( 'gzuncompress' ) ) 
     1792                        $type[] = 'compress;q=0.5'; 
     1793 
     1794                if( function_exists( 'gzdecode' ) ) 
     1795                        $type[] = 'gzip;q=0.5'; 
     1796 
     1797                return implode(', ', $type); 
     1798        } 
     1799 
     1800        /** 
     1801         * What enconding the content used when it was compressed to send in the headers. 
     1802         * 
     1803         * @since 2.8 
     1804         * 
     1805         * @return string Content-Encoding string to send in the header. 
     1806         */ 
     1807        function content_encoding() { 
     1808                return 'deflate'; 
     1809        } 
     1810 
     1811        /** 
     1812         * Whether the content be decoded based on the headers. 
     1813         * 
     1814         * @since 2.8 
     1815         * 
     1816         * @param array|string $headers All of the available headers. 
     1817         * @return bool 
     1818         */ 
     1819        function should_decode($headers) { 
     1820                if( is_array( $headers ) ) { 
     1821                        if( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) 
     1822                                return true; 
     1823                } else if( is_string( $headers ) ) { 
     1824                        return ( stripos($headers, 'content-encoding:') !== false ); 
     1825                } 
     1826 
     1827                return false; 
     1828        } 
     1829 
     1830        /** 
     1831         * Whether decompression and compression are supported by the PHP version. 
     1832         * 
     1833         * Each function is tested instead of checking for the zlib extension, to 
     1834         * ensure that the functions all exist in the PHP version and aren't 
     1835         * disabled. 
     1836         * 
     1837         * @since 2.8 
     1838         * 
     1839         * @return bool 
     1840         */ 
     1841        function is_available() { 
     1842                return ( function_exists('gzuncompress') || function_exists('gzdeflate') || 
     1843                                 function_exists('gzinflate') ); 
     1844        } 
     1845} 
     1846 
     1847/** 
    16011848 * Returns the initialized WP_Http Object 
    16021849 * 
    16031850 * @since 2.7.0