Proxy support. Props DD32. see #4011

git-svn-id: http://svn.automattic.com/wordpress/trunk@10864 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-04-03 18:23:13 +00:00
parent d859e9dd3b
commit 93c512ded4

View File

@ -118,7 +118,7 @@ class WP_Http {
}
}
if( has_filter('http_transport_get_debug') )
if ( has_filter('http_transport_get_debug') )
do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport);
if ( isset($args['blocking']) && !$args['blocking'] )
@ -166,7 +166,7 @@ class WP_Http {
}
}
if( has_filter('http_transport_post_debug') )
if ( has_filter('http_transport_post_debug') )
do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport);
if ( isset($args['blocking']) && !$args['blocking'] )
@ -243,16 +243,12 @@ class WP_Http {
// Determine if this is a https call and pass that on to the transport functions
// so that we can blacklist the transports that do not support ssl verification
if ( $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl' )
$r['ssl'] = true;
else
$r['ssl'] = false;
$r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
// Determine if this request is to OUR install of WordPress
if ( stristr(get_bloginfo('url'), $arrURL['host']) )
$r['local'] = true;
else
$r['local'] = false;
// Determine if this request is to OUR install of WordPress
$homeURL = parse_url(get_bloginfo('url'));
$r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
unset($homeURL);
if ( is_null( $r['headers'] ) )
$r['headers'] = array();
@ -275,7 +271,7 @@ class WP_Http {
// Construct Cookie: header if any cookies are set
WP_Http::buildCookieHeader( $r );
if( WP_Http_Encoding::is_available() )
if ( WP_Http_Encoding::is_available() )
$r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
if ( is_null($r['body']) ) {
@ -296,17 +292,17 @@ class WP_Http {
$transports = WP_Http::_postTransport($r);
}
if( has_action('http_api_debug') )
if ( has_action('http_api_debug') )
do_action('http_api_debug', $transports, 'transports_list');
$response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
foreach( (array) $transports as $transport ) {
foreach ( (array) $transports as $transport ) {
$response = $transport->request($url, $r);
if( has_action('http_api_debug') )
if ( has_action('http_api_debug') )
do_action( 'http_api_debug', $response, 'response', get_class($transport) );
if( ! is_wp_error($response) )
if ( ! is_wp_error($response) )
return $response;
}
@ -419,11 +415,12 @@ class WP_Http {
if ( !empty( $value ) ) {
$key = strtolower( $key );
if ( isset( $newheaders[$key] ) ) {
if ( isset( $newheaders[$key] ) )
$newheaders[$key] = array( $newheaders[$key], trim( $value ) );
} else {
else
$newheaders[$key] = trim( $value );
}
if ( 'set-cookie' == strtolower( $key ) )
$cookies[] = new WP_Http_Cookie( $value );
}
@ -448,9 +445,8 @@ class WP_Http {
function buildCookieHeader( &$r ) {
if ( ! empty($r['cookies']) ) {
$cookies_header = '';
foreach ( (array) $r['cookies'] as $cookie ) {
foreach ( (array) $r['cookies'] as $cookie )
$cookies_header .= $cookie->getHeaderValue() . '; ';
}
$cookies_header = substr( $cookies_header, 0, -2 );
$r['headers']['cookie'] = $cookies_header;
}
@ -494,7 +490,7 @@ class WP_Http {
$body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n");
if( "0" == trim($body) )
if ( "0" == trim($body) )
return $parsedBody; // Ignore footer headers.
} else {
return $body;
@ -510,7 +506,8 @@ class WP_Http {
*
* You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL in your wp-config.php file
* and this will only allow localhost and your blog to make requests. The constant
* WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests.
* WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests. The format of the
* WP_ACCESSABLE_HOSTS constant is a comma separated list of hostnames to allow.
*
* @since 2.8.0
* @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
@ -537,17 +534,20 @@ class WP_Http {
if ( $check === false )
return false;
$home = parse_url( get_bloginfo('site_url') );
$home = parse_url( get_option('siteurl') );
// Don't block requests back to ourselves by default
if ( $uri == 'localhost' || $uri == $home['host'] )
if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] )
return apply_filters('block_local_requests', false);
if ( defined('WP_ACCESSABLE_HOSTS') && is_array( WP_ACCESSABLE_HOSTS ) && in_array( $check['host'], WP_ACCESSABLE_HOSTS ) ) {
return false;
}
if ( !defined('WP_ACCESSABLE_HOSTS') )
return true;
return true;
static $accessable_hosts;
if ( null == $accessable_hosts )
$accessable_hosts = preg_split('|,\s*|', WP_ACCESSABLE_HOSTS);
return !in_array( $check['host'], $accessable_hosts ); //Inverse logic, If its in the array, then we can't access it.
}
}
@ -606,13 +606,11 @@ class WP_Http_Fsockopen {
if ( ! isset($arrURL['port']) ) {
if ( ($arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https') && extension_loaded('openssl') ) {
$arrURL['host'] = 'ssl://' . $arrURL['host'];
$arrURL['port'] = apply_filters('http_request_port', 443);
$arrURL['port'] = 443;
$secure_transport = true;
} else {
$arrURL['port'] = apply_filters('http_request_default_port', 80);
$arrURL['port'] = 80;
}
} else {
$arrURL['port'] = apply_filters('http_request_port', $arrURL['port'], $arrURL['host']);
}
// There are issues with the HTTPS and SSL protocols that cause errors that can be safely
@ -625,13 +623,12 @@ class WP_Http_Fsockopen {
$proxy = new WP_HTTP_Proxy();
if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) {
if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
$handle = @fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] );
else
$handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] );
}
else {
if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
} else {
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
$handle = fsockopen($proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] );
else
$handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] );
@ -648,22 +645,24 @@ class WP_Http_Fsockopen {
if ( false === $handle )
return new WP_Error('http_request_failed', $iError . ': ' . $strError);
// WordPress supports PHP 4.3, which has this function. Removed sanity checking for
// performance reasons.
stream_set_timeout($handle, $r['timeout'] );
$requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' );
$requestPath = empty($requestPath) ? '/' : $requestPath;
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field.
$requestPath = $url;
else
$requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' );
$strHeaders = '';
$strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";
if ( empty($requestPath) )
$requestPath .= '/';
if( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
$strHeaders .= 'Host: ' . $arrURL['host'] .':'. $arrURL['port'] . "\r\n";
$strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
$strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n";
else
$strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n";
if( isset($r['user-agent']) )
if ( isset($r['user-agent']) )
$strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n";
if ( is_array($r['headers']) ) {
@ -673,9 +672,8 @@ class WP_Http_Fsockopen {
$strHeaders .= $r['headers'];
}
if ( $proxy->use_authentication() ) {
if ( $proxy->use_authentication() )
$strHeaders .= $proxy->authentication_header() . "\r\n";
}
$strHeaders .= "\r\n";
@ -731,14 +729,20 @@ class WP_Http_Fsockopen {
* @static
* @return boolean False means this class can not be used, true means it can.
*/
function test($args = array()) {
function test( $args = array() ) {
if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours
return false;
if ( function_exists( 'fsockopen' ) && ( isset($args['ssl']) && !$args['ssl'] ) )
return apply_filters('use_fsockopen_transport', true);
$is_ssl = isset($args['ssl']) && $args['ssl'];
return false;
if ( ! $is_ssl && function_exists( 'fsockopen' ) )
$use = true;
elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) )
$use = true;
else
$use = false;
return apply_filters('use_fsockopen_transport', $use, $args);
}
}
@ -772,8 +776,6 @@ class WP_Http_Fopen {
* @return array 'headers', 'body', 'cookies' and 'response' keys.
*/
function request($url, $args = array()) {
global $http_response_header;
$defaults = array(
'method' => 'GET', 'timeout' => 5,
'redirection' => 5, 'httpversion' => '1.0',
@ -799,8 +801,6 @@ class WP_Http_Fopen {
if (! $handle)
return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
// WordPress supports PHP 4.3, which has this function. Removed sanity
// checking for performance reasons.
stream_set_timeout($handle, $r['timeout'] );
if ( ! $r['blocking'] ) {
@ -812,15 +812,14 @@ class WP_Http_Fopen {
while ( ! feof($handle) )
$strResponse .= fread($handle, 4096);
$theHeaders = '';
if ( function_exists('stream_get_meta_data') ) {
$meta = stream_get_meta_data($handle);
$theHeaders = $meta['wrapper_data'];
if( isset( $meta['wrapper_data']['headers'] ) )
if ( isset( $meta['wrapper_data']['headers'] ) )
$theHeaders = $meta['wrapper_data']['headers'];
} else {
if( ! isset( $http_response_header ) )
global $http_response_header;
//$http_response_header is a PHP reserved variable which is set in the current-scope when using the HTTP Wrapper
//see http://php.oregonstate.edu/manual/en/reserved.variables.httpresponseheader.php
$theHeaders = $http_response_header;
}
@ -844,19 +843,28 @@ class WP_Http_Fopen {
* @static
* @return boolean False means this class can not be used, true means it can.
*/
function test() {
function test($args = array()) {
if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
return false;
if (
( isset($args['ssl']) && !$args['ssl'] ) ||
( isset($args['local']) && $args['local'] == true && apply_filters('https_local_ssl_verify', true) != true ) ||
( isset($args['local']) && $args['local'] == false && apply_filters('https_ssl_verify', true) != true ) ||
( isset($args['sslverify']) && !$args['sslverify'] )
)
return apply_filters('use_fopen_transport', true);
$use = true;
return false;
//PHP does not verify SSL certs, We can only make a request via this transports if SSL Verification is turned off.
$is_ssl = isset($args['ssl']) && $args['ssl'];
if ( $is_ssl ) {
$is_local = isset($args['local']) && $args['local'];
$ssl_verify = isset($args['sslverify']) && $args['sslverify'];
if ( $is_local && true != apply_filters('https_local_ssl_verify', true) )
$use = true;
elseif ( !$is_local && true != apply_filters('https_ssl_verify', true) )
$use = true;
elseif ( !$ssl_verify )
$use = true;
else
$use = false;
}
return apply_filters('use_fopen_transport', $use, $args);
}
}
@ -910,16 +918,23 @@ class WP_Http_Streams {
return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
$url = str_replace($arrURL['scheme'], 'http', $url);
$url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url);
// Convert Header array to string.
$strHeaders = '';
if ( is_array( $r['headers'] ) )
foreach( $r['headers'] as $name => $value )
foreach ( $r['headers'] as $name => $value )
$strHeaders .= "{$name}: $value\r\n";
else if ( is_string( $r['headers'] ) )
$strHeaders = $r['headers'];
$is_local = isset($args['local']) && $args['local'];
$ssl_verify = isset($args['sslverify']) && $args['sslverify'];
if ( $is_local )
$ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
elseif ( ! $is_local )
$ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
$arrContext = array('http' =>
array(
'method' => strtoupper($r['method']),
@ -929,8 +944,8 @@ class WP_Http_Streams {
'header' => $strHeaders,
'timeout' => $r['timeout'],
'ssl' => array(
'verify_peer' => apply_filters('https_ssl_verify', $r['sslverify']),
'verify_host' => apply_filters('https_ssl_verify', $r['sslverify'])
'verify_peer' => $ssl_verify,
'verify_host' => $ssl_verify
)
)
);
@ -938,12 +953,12 @@ class WP_Http_Streams {
$proxy = new WP_HTTP_Proxy();
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
$arrContext['http']['proxy'] = 'tcp://'.$proxy->host().':'.$proxy->port();
$arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port();
$arrContext['http']['request_fulluri'] = true;
// We only support Basic authentication so this will only work if that is what your proxy supports.
if ( $proxy->use_authentication() ) {
if ( $proxy->use_authentication() )
$arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
}
}
if ( ! is_null($r['body']) && ! empty($r['body'] ) )
@ -975,7 +990,7 @@ class WP_Http_Streams {
fclose($handle);
$processedHeaders = array();
if( isset( $meta['wrapper_data']['headers'] ) )
if ( isset( $meta['wrapper_data']['headers'] ) )
$processedHeaders = WP_Http::processHeaders($meta['wrapper_data']['headers']);
else
$processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
@ -1005,7 +1020,19 @@ class WP_Http_Streams {
if ( version_compare(PHP_VERSION, '5.0', '<') )
return false;
return apply_filters('use_streams_transport', true);
//HTTPS via Proxy was added in 5.1.0
$is_ssl = isset($args['ssl']) && $args['ssl'];
if ( $is_ssl && version_compare(PHP_VERSION, '5.1.0', '<') ) {
$proxy = new WP_HTTP_Proxy();
/**
* No URL check, as its not currently passed to the ::test() function
* In the case where a Proxy is in use, Just bypass this transport for HTTPS.
*/
if ( $proxy->is_enabled() )
return false;
}
return apply_filters('use_streams_transport', true, $args);
}
}
@ -1069,7 +1096,14 @@ class WP_Http_ExtHTTP {
$arrURL = parse_url($url);
if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] )
$url = str_replace($arrURL['scheme'], 'http', $url);
$url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url);
$is_local = isset($args['local']) && $args['local'];
$ssl_verify = isset($args['sslverify']) && $args['sslverify'];
if ( $is_local )
$ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
elseif ( ! $is_local )
$ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
$options = array(
'timeout' => $r['timeout'],
@ -1078,8 +1112,8 @@ class WP_Http_ExtHTTP {
'useragent' => $r['user-agent'],
'headers' => $r['headers'],
'ssl' => array(
'verifypeer' => apply_filters('https_ssl_verify', $r['sslverify']),
'verifyhost' => apply_filters('https_ssl_verify', $r['sslverify'])
'verifypeer' => $ssl_verify,
'verifyhost' => $ssl_verify
)
);
@ -1139,10 +1173,7 @@ class WP_Http_ExtHTTP {
* @return boolean False means this class can not be used, true means it can.
*/
function test($args = array()) {
if ( function_exists('http_request') )
return apply_filters('use_http_extension_transport', true);
return false;
return apply_filters('use_http_extension_transport', function_exists('http_request'), $args );
}
}
@ -1199,7 +1230,6 @@ class WP_Http_Curl {
$proxy = new WP_HTTP_Proxy();
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
curl_setopt( $handle, CURLOPT_HTTPPROXYTUNNEL, true );
$isPHP5 = version_compare(PHP_VERSION, '5.0.0', '>=');
@ -1218,11 +1248,18 @@ class WP_Http_Curl {
curl_setopt( $handle, CURLOPT_PROXYUSERPWD, $proxy->authentication() );
}
}
$is_local = isset($args['local']) && $args['local'];
$ssl_verify = isset($args['sslverify']) && $args['sslverify'];
if ( $is_local )
$ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify);
elseif ( ! $is_local )
$ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
curl_setopt( $handle, CURLOPT_URL, $url);
curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, apply_filters('https_ssl_verify', $r['sslverify']) );
curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, apply_filters('https_ssl_verify', $r['sslverify']) );
curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify );
curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] );
curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
@ -1250,9 +1287,8 @@ class WP_Http_Curl {
if ( !empty( $r['headers'] ) ) {
// cURL expects full header strings in each element
$headers = array();
foreach ( $r['headers'] as $name => $value ) {
foreach ( $r['headers'] as $name => $value )
$headers[] = "{$name}: $value";
}
curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers );
}
@ -1317,7 +1353,7 @@ class WP_Http_Curl {
*/
function test($args = array()) {
if ( function_exists('curl_init') && function_exists('curl_exec') )
return apply_filters('use_curl_transport', true);
return apply_filters('use_curl_transport', true, $args);
return false;
}
@ -1338,14 +1374,14 @@ class WP_Http_Curl {
* <li>WP_PROXY_PASSWORD - Proxy password, if it requires authentication.</li>
* <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
* You do not need to have localhost and the blog host in this list, because they will not be passed
* through the proxy.</li>
* through the proxy. The list should be presented in a comma separated list</li>
* </ol>
*
* An example can be as seen below.
* <code>
* define('WP_PROXY_HOST', '192.168.84.101');
* define('WP_PROXY_PORT', '8080');
* define('WP_PROXY_BYPASS_HOSTS', array('localhost', 'www.example.com'));
* define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
* </code>
*
* @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress.
@ -1353,14 +1389,6 @@ class WP_Http_Curl {
*/
class WP_HTTP_Proxy {
function WP_HTTP_Proxy() {
$this->__construct();
}
function __construct() {
}
/**
* Whether proxy connection should be used.
*
@ -1371,7 +1399,7 @@ class WP_HTTP_Proxy {
* @return bool
*/
function is_enabled() {
return ( defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT') );
return defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT');
}
/**
@ -1384,7 +1412,7 @@ class WP_HTTP_Proxy {
* @return bool
*/
function use_authentication() {
return ( defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD') );
return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD');
}
/**
@ -1395,7 +1423,7 @@ class WP_HTTP_Proxy {
* @return string
*/
function host() {
if( defined('WP_PROXY_HOST') )
if ( defined('WP_PROXY_HOST') )
return WP_PROXY_HOST;
return '';
@ -1409,7 +1437,7 @@ class WP_HTTP_Proxy {
* @return string
*/
function port() {
if( defined('WP_PROXY_PORT') )
if ( defined('WP_PROXY_PORT') )
return WP_PROXY_PORT;
return '';
@ -1423,7 +1451,7 @@ class WP_HTTP_Proxy {
* @return string
*/
function username() {
if( defined('WP_PROXY_USERNAME') )
if ( defined('WP_PROXY_USERNAME') )
return WP_PROXY_USERNAME;
return '';
@ -1437,7 +1465,7 @@ class WP_HTTP_Proxy {
* @return string
*/
function password() {
if( defined('WP_PROXY_PASSWORD') )
if ( defined('WP_PROXY_PASSWORD') )
return WP_PROXY_PASSWORD;
return '';
@ -1451,7 +1479,7 @@ class WP_HTTP_Proxy {
* @return string
*/
function authentication() {
return $this->username() .':'. $this->password();
return $this->username() . ':' . $this->password();
}
/**
@ -1462,7 +1490,7 @@ class WP_HTTP_Proxy {
* @return string
*/
function authentication_header() {
return 'Proxy-Authentication: Basic '. base64_encode( $this->authentication() );
return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() );
}
/**
@ -1484,23 +1512,24 @@ class WP_HTTP_Proxy {
$check = @parse_url($uri);
// Malformed URL, can not process, but this could mean ssl, so let through anyway.
if( $check === false )
if ( $check === false )
return true;
$home = parse_url( get_bloginfo('site_url') );
$home = parse_url( get_option('siteurl') );
if ( $uri == 'localhost' || $uri == $home['host'] )
if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] )
return false;
if ( defined('WP_PROXY_BYPASS_HOSTS') && is_array( WP_PROXY_BYPASS_HOSTS ) && in_array( $check['host'], WP_PROXY_BYPASS_HOSTS ) ) {
return false;
}
return true;
if ( !defined('WP_PROXY_BYPASS_HOSTS') )
return true;
static $bypass_hosts;
if ( null == $bypass_hosts )
$bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS);
return !in_array( $check['host'], $bypass_hosts );
}
}
/**
* Internal representation of a single cookie.
*
@ -1744,17 +1773,17 @@ class WP_Http_Encoding {
function decompress( $compressed, $length = null ) {
$decompressed = gzinflate( $compressed );
if( false !== $decompressed )
if ( false !== $decompressed )
return $decompressed;
$decompressed = gzuncompress( $compressed );
if( false !== $decompressed )
if ( false !== $decompressed )
return $decompressed;
$decompressed = gzdecode( $compressed );
if( false !== $decompressed )
if ( false !== $decompressed )
return $decompressed;
return $compressed;
@ -1769,13 +1798,13 @@ class WP_Http_Encoding {
*/
function accept_encoding() {
$type = array();
if( function_exists( 'gzinflate' ) )
if ( function_exists( 'gzinflate' ) )
$type[] = 'deflate;q=1.0';
if( function_exists( 'gzuncompress' ) )
if ( function_exists( 'gzuncompress' ) )
$type[] = 'compress;q=0.5';
if( function_exists( 'gzdecode' ) )
if ( function_exists( 'gzdecode' ) )
$type[] = 'gzip;q=0.5';
return implode(', ', $type);
@ -1801,8 +1830,8 @@ class WP_Http_Encoding {
* @return bool
*/
function should_decode($headers) {
if( is_array( $headers ) ) {
if( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
if ( is_array( $headers ) ) {
if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
return true;
} else if( is_string( $headers ) ) {
return ( stripos($headers, 'content-encoding:') !== false );
@ -1823,8 +1852,7 @@ class WP_Http_Encoding {
* @return bool
*/
function is_available() {
return ( function_exists('gzuncompress') || function_exists('gzdeflate') ||
function_exists('gzinflate') );
return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') );
}
}
@ -1890,7 +1918,6 @@ function wp_remote_request($url, $args = array()) {
*/
function wp_remote_get($url, $args = array()) {
$objFetchSite = _wp_http_get_object();
return $objFetchSite->get($url, $args);
}