Ticket #4011: 4011.4.diff
File 4011.4.diff, 25.3 KB (added by , 16 years ago) |
---|
-
wp-includes/http.php
98 98 if ( true === WP_Http_ExtHttp::test($args) ) { 99 99 $working_transport['exthttp'] = new WP_Http_ExtHttp(); 100 100 $blocking_transport[] = &$working_transport['exthttp']; 101 } else 101 } elseif ( true === WP_Http_Curl::test($args) ) { 102 102 $working_transport['curl'] = new WP_Http_Curl(); 103 103 $blocking_transport[] = &$working_transport['curl']; 104 } else 104 } elseif ( true === WP_Http_Streams::test($args) ) { 105 105 $working_transport['streams'] = new WP_Http_Streams(); 106 106 $blocking_transport[] = &$working_transport['streams']; 107 } else 107 } elseif ( true === WP_Http_Fopen::test($args) ) { 108 108 $working_transport['fopen'] = new WP_Http_Fopen(); 109 109 $blocking_transport[] = &$working_transport['fopen']; 110 } else 110 } elseif ( true === WP_Http_Fsockopen::test($args) ) { 111 111 $working_transport['fsockopen'] = new WP_Http_Fsockopen(); 112 112 $blocking_transport[] = &$working_transport['fsockopen']; 113 113 } … … 118 118 } 119 119 } 120 120 121 if ( has_filter('http_transport_get_debug') )121 if ( has_filter('http_transport_get_debug') ) 122 122 do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport); 123 123 124 124 if ( isset($args['blocking']) && !$args['blocking'] ) … … 149 149 if ( true === WP_Http_ExtHttp::test($args) ) { 150 150 $working_transport['exthttp'] = new WP_Http_ExtHttp(); 151 151 $blocking_transport[] = &$working_transport['exthttp']; 152 } else 152 } elseif ( true === WP_Http_Curl::test($args) ) { 153 153 $working_transport['curl'] = new WP_Http_Curl(); 154 154 $blocking_transport[] = &$working_transport['curl']; 155 } else 155 } elseif ( true === WP_Http_Streams::test($args) ) { 156 156 $working_transport['streams'] = new WP_Http_Streams(); 157 157 $blocking_transport[] = &$working_transport['streams']; 158 } else 158 } elseif ( true === WP_Http_Fsockopen::test($args) ) { 159 159 $working_transport['fsockopen'] = new WP_Http_Fsockopen(); 160 160 $blocking_transport[] = &$working_transport['fsockopen']; 161 161 } … … 166 166 } 167 167 } 168 168 169 if ( has_filter('http_transport_post_debug') )169 if ( has_filter('http_transport_post_debug') ) 170 170 do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport); 171 171 172 172 if ( isset($args['blocking']) && !$args['blocking'] ) … … 243 243 244 244 // Determine if this is a https call and pass that on to the transport functions 245 245 // 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; 246 $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; 250 247 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; 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); 256 252 257 253 if ( is_null( $r['headers'] ) ) 258 254 $r['headers'] = array(); … … 275 271 // Construct Cookie: header if any cookies are set 276 272 WP_Http::buildCookieHeader( $r ); 277 273 278 if ( WP_Http_Encoding::is_available() )274 if ( WP_Http_Encoding::is_available() ) 279 275 $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding(); 280 276 281 277 if ( is_null($r['body']) ) { … … 296 292 $transports = WP_Http::_postTransport($r); 297 293 } 298 294 299 if ( has_action('http_api_debug') )295 if ( has_action('http_api_debug') ) 300 296 do_action('http_api_debug', $transports, 'transports_list'); 301 297 302 298 $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 ) { 304 300 $response = $transport->request($url, $r); 305 301 306 if ( has_action('http_api_debug') )302 if ( has_action('http_api_debug') ) 307 303 do_action( 'http_api_debug', $response, 'response', get_class($transport) ); 308 304 309 if ( ! is_wp_error($response) )305 if ( ! is_wp_error($response) ) 310 306 return $response; 311 307 } 312 308 … … 419 415 420 416 if ( !empty( $value ) ) { 421 417 $key = strtolower( $key ); 422 if ( isset( $newheaders[$key] ) ) { 418 419 if ( isset( $newheaders[$key] ) ) 423 420 $newheaders[$key] = array( $newheaders[$key], trim( $value ) ); 424 } else {421 else 425 422 $newheaders[$key] = trim( $value ); 426 } 423 427 424 if ( 'set-cookie' == strtolower( $key ) ) 428 425 $cookies[] = new WP_Http_Cookie( $value ); 429 426 } … … 448 445 function buildCookieHeader( &$r ) { 449 446 if ( ! empty($r['cookies']) ) { 450 447 $cookies_header = ''; 451 foreach ( (array) $r['cookies'] as $cookie ) {448 foreach ( (array) $r['cookies'] as $cookie ) 452 449 $cookies_header .= $cookie->getHeaderValue() . '; '; 453 }454 450 $cookies_header = substr( $cookies_header, 0, -2 ); 455 451 $r['headers']['cookie'] = $cookies_header; 456 452 } … … 494 490 495 491 $body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n"); 496 492 497 if ( "0" == trim($body) )493 if ( "0" == trim($body) ) 498 494 return $parsedBody; // Ignore footer headers. 499 495 } else { 500 496 return $body; … … 543 539 if ( $uri == 'localhost' || $uri == $home['host'] ) 544 540 return apply_filters('block_local_requests', false); 545 541 546 if ( defined('WP_ACCESSABLE_HOSTS') && is_array( WP_ACCESSABLE_HOSTS ) && in_array( $check['host'], WP_ACCESSABLE_HOSTS ) ) { 547 return false; 548 } 542 if ( defined('WP_ACCESSABLE_HOSTS') && is_array( WP_ACCESSABLE_HOSTS ) && in_array( $check['host'], WP_ACCESSABLE_HOSTS ) ) 543 return false; 549 544 550 545 return true; 551 546 } … … 588 583 if ( isset($r['headers']['User-Agent']) ) { 589 584 $r['user-agent'] = $r['headers']['User-Agent']; 590 585 unset($r['headers']['User-Agent']); 591 } else if( isset($r['headers']['user-agent']) ) {586 } elseif ( isset($r['headers']['user-agent']) ) { 592 587 $r['user-agent'] = $r['headers']['user-agent']; 593 588 unset($r['headers']['user-agent']); 594 589 } … … 606 601 if ( ! isset($arrURL['port']) ) { 607 602 if ( ($arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https') && extension_loaded('openssl') ) { 608 603 $arrURL['host'] = 'ssl://' . $arrURL['host']; 609 $arrURL['port'] = apply_filters('http_request_port', 443);604 $arrURL['port'] = 443; 610 605 $secure_transport = true; 611 606 } else { 612 $arrURL['port'] = apply_filters('http_request_default_port', 80);607 $arrURL['port'] = 80; 613 608 } 614 } else {615 $arrURL['port'] = apply_filters('http_request_port', $arrURL['port'], $arrURL['host']);616 609 } 617 610 618 611 // There are issues with the HTTPS and SSL protocols that cause errors that can be safely … … 625 618 $proxy = new WP_HTTP_Proxy(); 626 619 627 620 if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) { 628 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )621 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 629 622 $handle = @fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] ); 630 623 else 631 624 $handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); 632 } 633 else { 634 if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 625 } else { 626 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 635 627 $handle = fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] ); 636 628 else 637 629 $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); … … 648 640 if ( false === $handle ) 649 641 return new WP_Error('http_request_failed', $iError . ': ' . $strError); 650 642 651 // WordPress supports PHP 4.3, which has this function. Removed sanity checking for652 // performance reasons.653 643 stream_set_timeout($handle, $r['timeout'] ); 654 644 655 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); 656 $requestPath = empty($requestPath) ? '/' : $requestPath; 645 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field. 646 $requestPath = $url; 647 else 648 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); 657 649 658 $strHeaders = '';659 $strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";650 if ( empty($requestPath) ) 651 $requestPath .= '/'; 660 652 661 if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 662 $strHeaders .= 'Host: ' . $arrURL['host'] .':'. $arrURL['port'] . "\r\n"; 653 $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; 654 655 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) 656 $strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n"; 663 657 else 664 658 $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; 665 659 666 if ( isset($r['user-agent']) )660 if ( isset($r['user-agent']) ) 667 661 $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n"; 668 662 669 663 if ( is_array($r['headers']) ) { … … 673 667 $strHeaders .= $r['headers']; 674 668 } 675 669 676 if ( $proxy->use_authentication() ) {670 if ( $proxy->use_authentication() ) 677 671 $strHeaders .= $proxy->authentication_header() . "\r\n"; 678 }679 672 680 673 $strHeaders .= "\r\n"; 681 674 … … 731 724 * @static 732 725 * @return boolean False means this class can not be used, true means it can. 733 726 */ 734 function test( $args = array()) {727 function test( $args = array() ) { 735 728 if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours 736 729 return false; 737 730 738 if ( function_exists( 'fsockopen' ) && ( isset($args['ssl']) && !$args['ssl'] ) ) 739 return apply_filters('use_fsockopen_transport', true); 731 $is_ssl = isset($args['ssl']) && $args['ssl']; 740 732 741 return false; 733 if ( ! $is_ssl && function_exists( 'fsockopen' ) ) 734 $use = true; 735 elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) ) 736 $use = true; 737 else 738 $use = false; 739 740 return apply_filters('use_fsockopen_transport', $use, $args); 742 741 } 743 742 } 744 743 … … 772 771 * @return array 'headers', 'body', 'cookies' and 'response' keys. 773 772 */ 774 773 function request($url, $args = array()) { 775 global $http_response_header;776 777 774 $defaults = array( 778 775 'method' => 'GET', 'timeout' => 5, 779 776 'redirection' => 5, 'httpversion' => '1.0', … … 799 796 if (! $handle) 800 797 return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); 801 798 802 // WordPress supports PHP 4.3, which has this function. Removed sanity803 // checking for performance reasons.804 799 stream_set_timeout($handle, $r['timeout'] ); 805 800 806 801 if ( ! $r['blocking'] ) { … … 812 807 while ( ! feof($handle) ) 813 808 $strResponse .= fread($handle, 4096); 814 809 815 $theHeaders = '';816 810 if ( function_exists('stream_get_meta_data') ) { 817 811 $meta = stream_get_meta_data($handle); 818 812 $theHeaders = $meta['wrapper_data']; 819 if ( isset( $meta['wrapper_data']['headers'] ) )813 if ( isset( $meta['wrapper_data']['headers'] ) ) 820 814 $theHeaders = $meta['wrapper_data']['headers']; 821 815 } else { 822 if( ! isset( $http_response_header ) )823 global $http_response_header;816 //$http_response_header is a PHP reserved variable which is set in the current-scope when using the HTTP Wrapper 817 //see http://php.oregonstate.edu/manual/en/reserved.variables.httpresponseheader.php 824 818 $theHeaders = $http_response_header; 825 819 } 826 820 … … 844 838 * @static 845 839 * @return boolean False means this class can not be used, true means it can. 846 840 */ 847 function test( ) {841 function test($args = array()) { 848 842 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) ) 849 843 return false; 850 844 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); 845 $use = true; 858 846 859 return false; 847 //PHP does not verify SSL certs, We can only make a request via this transports if SSL Verification is turned off. 848 $is_ssl = isset($args['ssl']) && $args['ssl']; 849 if ( $is_ssl ) { 850 $is_local = isset($args['local']) && $args['local']; 851 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 852 if ( $is_local && true != apply_filters('https_local_ssl_verify', true) ) 853 $use = true; 854 elseif ( !$is_local && true != apply_filters('https_ssl_verify', true) ) 855 $use = true; 856 elseif ( !$ssl_verify ) 857 $use = true; 858 else 859 $use = false; 860 } 861 862 return apply_filters('use_fopen_transport', $use, $args); 860 863 } 861 864 } 862 865 … … 896 899 if ( isset($r['headers']['User-Agent']) ) { 897 900 $r['user-agent'] = $r['headers']['User-Agent']; 898 901 unset($r['headers']['User-Agent']); 899 } else if( isset($r['headers']['user-agent']) ) {902 } elseif ( isset($r['headers']['user-agent']) ) { 900 903 $r['user-agent'] = $r['headers']['user-agent']; 901 904 unset($r['headers']['user-agent']); 902 905 } … … 910 913 return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url)); 911 914 912 915 if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] ) 913 $url = str_replace($arrURL['scheme'], 'http', $url);916 $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url); 914 917 915 918 // Convert Header array to string. 916 919 $strHeaders = ''; 917 920 if ( is_array( $r['headers'] ) ) 918 foreach ( $r['headers'] as $name => $value )921 foreach ( $r['headers'] as $name => $value ) 919 922 $strHeaders .= "{$name}: $value\r\n"; 920 else 923 elseif ( is_string( $r['headers'] ) ) 921 924 $strHeaders = $r['headers']; 922 925 926 $is_local = isset($args['local']) && $args['local']; 927 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 928 if ( $is_local ) 929 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 930 elseif ( ! $is_local ) 931 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 932 923 933 $arrContext = array('http' => 924 934 array( 925 935 'method' => strtoupper($r['method']), … … 929 939 'header' => $strHeaders, 930 940 'timeout' => $r['timeout'], 931 941 'ssl' => array( 932 'verify_peer' => apply_filters('https_ssl_verify', $r['sslverify']),933 'verify_host' => apply_filters('https_ssl_verify', $r['sslverify'])942 'verify_peer' => $ssl_verify, 943 'verify_host' => $ssl_verify 934 944 ) 935 945 ) 936 946 ); 937 947 938 948 $proxy = new WP_HTTP_Proxy(); 939 949 940 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 941 $arrContext['http']['proxy'] = 'tcp://'.$proxy->host().':'.$proxy->port(); 950 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 951 $arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port(); 952 $arrContext['http']['request_fulluri'] = true; 942 953 943 954 // We only support Basic authentication so this will only work if that is what your proxy supports. 944 if ( $proxy->use_authentication() ) {955 if ( $proxy->use_authentication() ) 945 956 $arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n"; 946 }947 957 } 948 958 949 959 if ( ! is_null($r['body']) && ! empty($r['body'] ) ) … … 975 985 fclose($handle); 976 986 977 987 $processedHeaders = array(); 978 if ( isset( $meta['wrapper_data']['headers'] ) )988 if ( isset( $meta['wrapper_data']['headers'] ) ) 979 989 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']); 980 990 else 981 991 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']); … … 1005 1015 if ( version_compare(PHP_VERSION, '5.0', '<') ) 1006 1016 return false; 1007 1017 1008 return apply_filters('use_streams_transport', true); 1018 //HTTPS via Proxy was added in 5.1.0 1019 $is_ssl = isset($args['ssl']) && $args['ssl']; 1020 if ( $is_ssl && version_compare(PHP_VERSION, '5.1.0', '<') ) { 1021 $proxy = new WP_HTTP_Proxy(); 1022 /** 1023 * No URL check, as its not currently passed to the ::test() function 1024 * In the case where a Proxy is in use, Just bypass this transport for HTTPS. 1025 */ 1026 if ( $proxy->is_enabled() ) 1027 return false; 1028 } 1029 1030 return apply_filters('use_streams_transport', true, $args); 1009 1031 } 1010 1032 } 1011 1033 … … 1046 1068 if ( isset($r['headers']['User-Agent']) ) { 1047 1069 $r['user-agent'] = $r['headers']['User-Agent']; 1048 1070 unset($r['headers']['User-Agent']); 1049 } else if( isset($r['headers']['user-agent']) ) {1071 } elseif ( isset($r['headers']['user-agent']) ) { 1050 1072 $r['user-agent'] = $r['headers']['user-agent']; 1051 1073 unset($r['headers']['user-agent']); 1052 1074 } … … 1069 1091 $arrURL = parse_url($url); 1070 1092 1071 1093 if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] ) 1072 $url = str_replace($arrURL['scheme'], 'http', $url);1094 $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url); 1073 1095 1096 $is_local = isset($args['local']) && $args['local']; 1097 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 1098 if ( $is_local ) 1099 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 1100 elseif ( ! $is_local ) 1101 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 1102 1074 1103 $options = array( 1075 1104 'timeout' => $r['timeout'], 1076 1105 'connecttimeout' => $r['timeout'], … … 1078 1107 'useragent' => $r['user-agent'], 1079 1108 'headers' => $r['headers'], 1080 1109 'ssl' => array( 1081 'verifypeer' => apply_filters('https_ssl_verify', $r['sslverify']),1082 'verifyhost' => apply_filters('https_ssl_verify', $r['sslverify'])1110 'verifypeer' => $ssl_verify, 1111 'verifyhost' => $ssl_verify 1083 1112 ) 1084 1113 ); 1085 1114 … … 1139 1168 * @return boolean False means this class can not be used, true means it can. 1140 1169 */ 1141 1170 function test($args = array()) { 1142 if ( function_exists('http_request') ) 1143 return apply_filters('use_http_extension_transport', true); 1144 1145 return false; 1171 return apply_filters('use_http_extension_transport', function_exists('http_request'), $args ); 1146 1172 } 1147 1173 } 1148 1174 … … 1180 1206 if ( isset($r['headers']['User-Agent']) ) { 1181 1207 $r['user-agent'] = $r['headers']['User-Agent']; 1182 1208 unset($r['headers']['User-Agent']); 1183 } else if( isset($r['headers']['user-agent']) ) {1209 } elseif ( isset($r['headers']['user-agent']) ) { 1184 1210 $r['user-agent'] = $r['headers']['user-agent']; 1185 1211 unset($r['headers']['user-agent']); 1186 1212 } … … 1199 1225 $proxy = new WP_HTTP_Proxy(); 1200 1226 1201 1227 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 1202 curl_setopt( $handle, CURLOPT_HTTPPROXYTUNNEL, true );1203 1228 1204 1229 $isPHP5 = version_compare(PHP_VERSION, '5.0.0', '>='); 1205 1230 … … 1218 1243 curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() ); 1219 1244 } 1220 1245 } 1246 1247 $is_local = isset($args['local']) && $args['local']; 1248 $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 1249 if ( $is_local ) 1250 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 1251 elseif ( ! $is_local ) 1252 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 1221 1253 1222 1254 curl_setopt( $handle, CURLOPT_URL, $url); 1223 1255 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']));1256 curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify ); 1257 curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify ); 1226 1258 curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] ); 1227 1259 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] ); 1228 1260 curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] ); … … 1250 1282 if ( !empty( $r['headers'] ) ) { 1251 1283 // cURL expects full header strings in each element 1252 1284 $headers = array(); 1253 foreach ( $r['headers'] as $name => $value ) {1285 foreach ( $r['headers'] as $name => $value ) 1254 1286 $headers[] = "{$name}: $value"; 1255 }1256 1287 curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); 1257 1288 } 1258 1289 … … 1317 1348 */ 1318 1349 function test($args = array()) { 1319 1350 if ( function_exists('curl_init') && function_exists('curl_exec') ) 1320 return apply_filters('use_curl_transport', true);1351 return apply_filters('use_curl_transport', true, $args); 1321 1352 1322 1353 return false; 1323 1354 } … … 1353 1384 */ 1354 1385 class WP_HTTP_Proxy { 1355 1386 1356 function WP_HTTP_Proxy() {1357 $this->__construct();1358 }1359 1360 function __construct() {1361 1362 }1363 1364 1387 /** 1365 1388 * Whether proxy connection should be used. 1366 1389 * … … 1371 1394 * @return bool 1372 1395 */ 1373 1396 function is_enabled() { 1374 return ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT'));1397 return defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT'); 1375 1398 } 1376 1399 1377 1400 /** … … 1384 1407 * @return bool 1385 1408 */ 1386 1409 function use_authentication() { 1387 return ( defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'));1410 return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'); 1388 1411 } 1389 1412 1390 1413 /** … … 1395 1418 * @return string 1396 1419 */ 1397 1420 function host() { 1398 if ( defined('WP_PROXY_HOST') )1421 if ( defined('WP_PROXY_HOST') ) 1399 1422 return WP_PROXY_HOST; 1400 1423 1401 1424 return ''; … … 1409 1432 * @return string 1410 1433 */ 1411 1434 function port() { 1412 if ( defined('WP_PROXY_PORT') )1435 if ( defined('WP_PROXY_PORT') ) 1413 1436 return WP_PROXY_PORT; 1414 1437 1415 1438 return ''; … … 1423 1446 * @return string 1424 1447 */ 1425 1448 function username() { 1426 if ( defined('WP_PROXY_USERNAME') )1449 if ( defined('WP_PROXY_USERNAME') ) 1427 1450 return WP_PROXY_USERNAME; 1428 1451 1429 1452 return ''; … … 1437 1460 * @return string 1438 1461 */ 1439 1462 function password() { 1440 if ( defined('WP_PROXY_PASSWORD') )1463 if ( defined('WP_PROXY_PASSWORD') ) 1441 1464 return WP_PROXY_PASSWORD; 1442 1465 1443 1466 return ''; … … 1451 1474 * @return string 1452 1475 */ 1453 1476 function authentication() { 1454 return $this->username() . ':'. $this->password();1477 return $this->username() . ':' . $this->password(); 1455 1478 } 1456 1479 1457 1480 /** … … 1462 1485 * @return string 1463 1486 */ 1464 1487 function authentication_header() { 1465 return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() );1488 return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() ); 1466 1489 } 1467 1490 1468 1491 /** … … 1484 1507 $check = @parse_url($uri); 1485 1508 1486 1509 // Malformed URL, can not process, but this could mean ssl, so let through anyway. 1487 if ( $check === false )1510 if ( $check === false ) 1488 1511 return true; 1489 1512 1490 1513 $home = parse_url( get_bloginfo('site_url') ); … … 1492 1515 if ( $uri == 'localhost' || $uri == $home['host'] ) 1493 1516 return false; 1494 1517 1495 if ( defined('WP_PROXY_BYPASS_HOSTS') && is_array( WP_PROXY_BYPASS_HOSTS ) && in_array( $check['host'], WP_PROXY_BYPASS_HOSTS ) ) {1518 if ( defined('WP_PROXY_BYPASS_HOSTS') && is_array( WP_PROXY_BYPASS_HOSTS ) && in_array( $check['host'], WP_PROXY_BYPASS_HOSTS ) ) 1496 1519 return false; 1497 }1498 1520 1499 1521 return true; 1500 1522 } 1501 1523 } 1502 1503 1504 1524 /** 1505 1525 * Internal representation of a single cookie. 1506 1526 * … … 1744 1764 function decompress( $compressed, $length = null ) { 1745 1765 $decompressed = gzinflate( $compressed ); 1746 1766 1747 if ( false !== $decompressed )1767 if ( false !== $decompressed ) 1748 1768 return $decompressed; 1749 1769 1750 1770 $decompressed = gzuncompress( $compressed ); 1751 1771 1752 if ( false !== $decompressed )1772 if ( false !== $decompressed ) 1753 1773 return $decompressed; 1754 1774 1755 1775 $decompressed = gzdecode( $compressed ); 1756 1776 1757 if ( false !== $decompressed )1777 if ( false !== $decompressed ) 1758 1778 return $decompressed; 1759 1779 1760 1780 return $compressed; … … 1769 1789 */ 1770 1790 function accept_encoding() { 1771 1791 $type = array(); 1772 if ( function_exists( 'gzinflate' ) )1792 if ( function_exists( 'gzinflate' ) ) 1773 1793 $type[] = 'deflate;q=1.0'; 1774 1794 1775 if ( function_exists( 'gzuncompress' ) )1795 if ( function_exists( 'gzuncompress' ) ) 1776 1796 $type[] = 'compress;q=0.5'; 1777 1797 1778 if ( function_exists( 'gzdecode' ) )1798 if ( function_exists( 'gzdecode' ) ) 1779 1799 $type[] = 'gzip;q=0.5'; 1780 1800 1781 1801 return implode(', ', $type); … … 1801 1821 * @return bool 1802 1822 */ 1803 1823 function should_decode($headers) { 1804 if ( is_array( $headers ) ) {1805 if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )1824 if ( is_array( $headers ) ) { 1825 if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) 1806 1826 return true; 1807 } else if( is_string( $headers ) ) {1827 } elseif ( is_string( $headers ) ) { 1808 1828 return ( stripos($headers, 'content-encoding:') !== false ); 1809 1829 } 1810 1830 … … 1823 1843 * @return bool 1824 1844 */ 1825 1845 function is_available() { 1826 return ( function_exists('gzuncompress') || function_exists('gzdeflate') || 1827 function_exists('gzinflate') ); 1846 return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') ); 1828 1847 } 1829 1848 } 1830 1849 … … 1890 1909 */ 1891 1910 function wp_remote_get($url, $args = array()) { 1892 1911 $objFetchSite = _wp_http_get_object(); 1893 1894 1912 return $objFetchSite->get($url, $args); 1895 1913 } 1896 1914