Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/wp-includes/class-http.php

    r17282 r15283  
    239239                        return $pre;
    240240
    241                 $arrURL = parse_url( $url );
     241                $arrURL = parse_url($url);
    242242
    243243                if ( empty( $url ) || empty( $arrURL['scheme'] ) )
    … …  
    245245
    246246                if ( $this->block_request( $url ) )
    247                         return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) );
     247                        return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
    248248
    249249                // Determine if this is a https call and pass that on to the transport functions
    … …  
    252252
    253253                // Determine if this request is to OUR install of WordPress
    254                 $homeURL = parse_url( get_bloginfo( 'url' ) );
     254                $homeURL = parse_url( get_bloginfo('url') );
    255255                $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
    256                 unset( $homeURL );
     256                unset($homeURL);
    257257
    258258                if ( is_null( $r['headers'] ) )
    259259                        $r['headers'] = array();
    260260
    261                 if ( ! is_array( $r['headers'] ) ) {
    262                         $processedHeaders = WP_Http::processHeaders( $r['headers'] );
     261                if ( ! is_array($r['headers']) ) {
     262                        $processedHeaders = WP_Http::processHeaders($r['headers']);
    263263                        $r['headers'] = $processedHeaders['headers'];
    264264                }
    265265
    266                 if ( isset( $r['headers']['User-Agent'] ) ) {
     266                if ( isset($r['headers']['User-Agent']) ) {
    267267                        $r['user-agent'] = $r['headers']['User-Agent'];
    268                         unset( $r['headers']['User-Agent'] );
    269                 }
    270 
    271                 if ( isset( $r['headers']['user-agent'] ) ) {
     268                        unset($r['headers']['User-Agent']);
     269                }
     270
     271                if ( isset($r['headers']['user-agent']) ) {
    272272                        $r['user-agent'] = $r['headers']['user-agent'];
    273                         unset( $r['headers']['user-agent'] );
     273                        unset($r['headers']['user-agent']);
    274274                }
    275275
    … …  
    281281
    282282                if ( empty($r['body']) ) {
    283                         $r['body'] = null;
    284283                        // Some servers fail when sending content without the content-length header being set.
    285284                        // Also, to fix another bug, we only send when doing POST and PUT and the content-length
    286285                        // header isn't already set.
    287                         if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) )
     286                        if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) )
    288287                                $r['headers']['Content-Length'] = 0;
    289288
    … …  
    291290                        // this case is simply that we aren't sending any bodies and to get the transports that
    292291                        // don't support sending bodies along with those which do.
    293                         $transports = WP_Http::_getTransport( $r );
     292                        $transports = WP_Http::_getTransport($r);
    294293                } else {
    295294                        if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
    296295                                if ( ! version_compare(phpversion(), '5.1.2', '>=') )
    297                                         $r['body'] = _http_build_query( $r['body'], null, '&' );
     296                                        $r['body'] = _http_build_query($r['body'], null, '&');
    298297                                else
    299                                         $r['body'] = http_build_query( $r['body'], null, '&' );
    300                                 $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' );
    301                                 $r['headers']['Content-Length'] = strlen( $r['body'] );
     298                                        $r['body'] = http_build_query($r['body'], null, '&');
     299                                $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
     300                                $r['headers']['Content-Length'] = strlen($r['body']);
    302301                        }
    303302
    304303                        if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
    305                                 $r['headers']['Content-Length'] = strlen( $r['body'] );
     304                                $r['headers']['Content-Length'] = strlen($r['body']);
    306305
    307306                        // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
    … …  
    309308                        // support sending the body. Not all do, depending on the limitations of the PHP core
    310309                        // limitations.
    311                         $transports = WP_Http::_postTransport( $r );
     310                        $transports = WP_Http::_postTransport($r);
    312311                }
    313312
    … …  
    316315                $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
    317316                foreach ( (array) $transports as $transport ) {
    318                         $response = $transport->request( $url, $r );
    319 
    320                         do_action( 'http_api_debug', $response, 'response', get_class( $transport ) );
    321 
    322                         if ( ! is_wp_error( $response ) )
     317                        $response = $transport->request($url, $r);
     318
     319                        do_action( 'http_api_debug', $response, 'response', get_class($transport) );
     320
     321                        if ( ! is_wp_error($response) )
    323322                                return apply_filters( 'http_response', $response, $r, $url );
    324323                }
    … …  
    455454                                        $newheaders[$key] = trim( $value );
    456455                                }
    457                                 if ( 'set-cookie' == $key )
     456                                if ( 'set-cookie' == strtolower( $key ) )
    458457                                        $cookies[] = new WP_Http_Cookie( $value );
    459458                        }
    … …  
    542541         * file and this will only allow localhost and your blog to make requests. The constant
    543542         * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
    544          * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains
    545          * are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted.
     543         * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
    546544         *
    547545         * @since 2.8.0
    548546         * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
    549          * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS
    550547         *
    551548         * @param string $uri URI of url.
    … …  
    581578
    582579                static $accessible_hosts;
    583                 static $wildcard_regex = false;
    584                 if ( null == $accessible_hosts ) {
     580                if ( null == $accessible_hosts )
    585581                        $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
    586582
    587                         if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) {
    588                                 $wildcard_regex = array();
    589                                 foreach ( $accessible_hosts as $host )
    590                                         $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/'));
    591                                 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i';
    592                         }
    593                 }
    594 
    595                 if ( !empty($wildcard_regex) )
    596                         return !preg_match($wildcard_regex, $check['host']);
    597                 else
    598                         return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it.
    599 
    600 
    601 
     583                return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it.
    602584        }
    603585}
    … …  
    640622                        $r['user-agent'] = $r['headers']['User-Agent'];
    641623                        unset($r['headers']['User-Agent']);
    642                 } else if ( isset($r['headers']['user-agent']) ) {
     624                } else if( isset($r['headers']['user-agent']) ) {
    643625                        $r['user-agent'] = $r['headers']['user-agent'];
    644626                        unset($r['headers']['user-agent']);
    … …  
    992974                        $r['user-agent'] = $r['headers']['User-Agent'];
    993975                        unset($r['headers']['User-Agent']);
    994                 } else if ( isset($r['headers']['user-agent']) ) {
     976                } else if( isset($r['headers']['user-agent']) ) {
    995977                        $r['user-agent'] = $r['headers']['user-agent'];
    996978                        unset($r['headers']['user-agent']);
    … …  
    11391121 * @since 2.7.0
    11401122 */
    1141 class WP_Http_ExtHttp {
     1123class WP_Http_ExtHTTP {
    11421124        /**
    11431125         * Send a HTTP request to a URI using HTTP extension.
    … …  
    11651147                        $r['user-agent'] = $r['headers']['User-Agent'];
    11661148                        unset($r['headers']['User-Agent']);
    1167                 } else if ( isset($r['headers']['user-agent']) ) {
     1149                } else if( isset($r['headers']['user-agent']) ) {
    11681150                        $r['user-agent'] = $r['headers']['user-agent'];
    11691151                        unset($r['headers']['user-agent']);
    … …  
    13151297                        $r['user-agent'] = $r['headers']['User-Agent'];
    13161298                        unset($r['headers']['User-Agent']);
    1317                 } else if ( isset($r['headers']['user-agent']) ) {
     1299                } else if( isset($r['headers']['user-agent']) ) {
    13181300                        $r['user-agent'] = $r['headers']['user-agent'];
    13191301                        unset($r['headers']['user-agent']);
    … …  
    14271409                        else
    14281410                                $theBody = '';
    1429                         if ( false !== strpos($theHeaders, "\r\n\r\n") ) {
     1411                        if ( false !== strrpos($theHeaders, "\r\n\r\n") ) {
    14301412                                $headerParts = explode("\r\n\r\n", $theHeaders);
    14311413                                $theHeaders = $headerParts[ count($headerParts) -1 ];
    … …  
    14971479 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
    14981480 * You do not need to have localhost and the blog host in this list, because they will not be passed
    1499  * through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org</li>
     1481 * through the proxy. The list should be presented in a comma separated list</li>
    15001482 * </ol>
    15011483 *
    … …  
    15041486 * define('WP_PROXY_HOST', '192.168.84.101');
    15051487 * define('WP_PROXY_PORT', '8080');
    1506  * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org');
     1488 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
    15071489 * </code>
    15081490 *
    15091491 * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress.
    1510  * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_PROXY_BYPASS_HOSTS
    15111492 * @since 2.8
    15121493 */
    … …  
    16251606         *
    16261607         * @uses WP_PROXY_BYPASS_HOSTS
    1627          * @since 2.8.0
     1608         * @since unknown
    16281609         *
    16291610         * @param string $uri URI to check.
    … …  
    16481629
    16491630                static $bypass_hosts;
    1650                 static $wildcard_regex = false;
    1651                 if ( null == $bypass_hosts ) {
     1631                if ( null == $bypass_hosts )
    16521632                        $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS);
    16531633
    1654                         if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) {
    1655                                 $wildcard_regex = array();
    1656                                 foreach ( $bypass_hosts as $host )
    1657                                         $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/'));
    1658                                 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i';
    1659                         }
    1660                 }
    1661 
    1662                 if ( !empty($wildcard_regex) )
    1663                         return !preg_match($wildcard_regex, $check['host']);
    1664                 else
    1665                         return !in_array( $check['host'], $bypass_hosts );
     1634                return !in_array( $check['host'], $bypass_hosts );
    16661635        }
    16671636}
Note: See TracChangeset for help on using the changeset viewer.