Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r15283 r17282  
    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;
    283284            // Some servers fail when sending content without the content-length header being set.
    284285            // Also, to fix another bug, we only send when doing POST and PUT and the content-length
    285286            // header isn't already set.
    286             if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) )
     287            if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) )
    287288                $r['headers']['Content-Length'] = 0;
    288289
     
    290291            // this case is simply that we aren't sending any bodies and to get the transports that
    291292            // don't support sending bodies along with those which do.
    292             $transports = WP_Http::_getTransport($r);
     293            $transports = WP_Http::_getTransport( $r );
    293294        } else {
    294295            if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
    295296                if ( ! version_compare(phpversion(), '5.1.2', '>=') )
    296                     $r['body'] = _http_build_query($r['body'], null, '&');
     297                    $r['body'] = _http_build_query( $r['body'], null, '&' );
    297298                else
    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']);
     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'] );
    301302            }
    302303
    303304            if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
    304                 $r['headers']['Content-Length'] = strlen($r['body']);
     305                $r['headers']['Content-Length'] = strlen( $r['body'] );
    305306
    306307            // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
     
    308309            // support sending the body. Not all do, depending on the limitations of the PHP core
    309310            // limitations.
    310             $transports = WP_Http::_postTransport($r);
     311            $transports = WP_Http::_postTransport( $r );
    311312        }
    312313
     
    315316        $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
    316317        foreach ( (array) $transports as $transport ) {
    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) )
     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 ) )
    322323                return apply_filters( 'http_response', $response, $r, $url );
    323324        }
     
    454455                    $newheaders[$key] = trim( $value );
    455456                }
    456                 if ( 'set-cookie' == strtolower( $key ) )
     457                if ( 'set-cookie' == $key )
    457458                    $cookies[] = new WP_Http_Cookie( $value );
    458459            }
     
    541542     * file and this will only allow localhost and your blog to make requests. The constant
    542543     * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
    543      * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow.
     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.
    544546     *
    545547     * @since 2.8.0
    546548     * @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
    547550     *
    548551     * @param string $uri URI of url.
     
    578581
    579582        static $accessible_hosts;
    580         if ( null == $accessible_hosts )
     583        static $wildcard_regex = false;
     584        if ( null == $accessible_hosts ) {
    581585            $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
    582586
    583         return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it.
     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
    584602    }
    585603}
     
    622640            $r['user-agent'] = $r['headers']['User-Agent'];
    623641            unset($r['headers']['User-Agent']);
    624         } else if( isset($r['headers']['user-agent']) ) {
     642        } else if ( isset($r['headers']['user-agent']) ) {
    625643            $r['user-agent'] = $r['headers']['user-agent'];
    626644            unset($r['headers']['user-agent']);
     
    974992            $r['user-agent'] = $r['headers']['User-Agent'];
    975993            unset($r['headers']['User-Agent']);
    976         } else if( isset($r['headers']['user-agent']) ) {
     994        } else if ( isset($r['headers']['user-agent']) ) {
    977995            $r['user-agent'] = $r['headers']['user-agent'];
    978996            unset($r['headers']['user-agent']);
     
    11211139 * @since 2.7.0
    11221140 */
    1123 class WP_Http_ExtHTTP {
     1141class WP_Http_ExtHttp {
    11241142    /**
    11251143     * Send a HTTP request to a URI using HTTP extension.
     
    11471165            $r['user-agent'] = $r['headers']['User-Agent'];
    11481166            unset($r['headers']['User-Agent']);
    1149         } else if( isset($r['headers']['user-agent']) ) {
     1167        } else if ( isset($r['headers']['user-agent']) ) {
    11501168            $r['user-agent'] = $r['headers']['user-agent'];
    11511169            unset($r['headers']['user-agent']);
     
    12971315            $r['user-agent'] = $r['headers']['User-Agent'];
    12981316            unset($r['headers']['User-Agent']);
    1299         } else if( isset($r['headers']['user-agent']) ) {
     1317        } else if ( isset($r['headers']['user-agent']) ) {
    13001318            $r['user-agent'] = $r['headers']['user-agent'];
    13011319            unset($r['headers']['user-agent']);
     
    14091427            else
    14101428                $theBody = '';
    1411             if ( false !== strrpos($theHeaders, "\r\n\r\n") ) {
     1429            if ( false !== strpos($theHeaders, "\r\n\r\n") ) {
    14121430                $headerParts = explode("\r\n\r\n", $theHeaders);
    14131431                $theHeaders = $headerParts[ count($headerParts) -1 ];
     
    14791497 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
    14801498 * You do not need to have localhost and the blog host in this list, because they will not be passed
    1481  * through the proxy. The list should be presented in a comma separated list</li>
     1499 * through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org</li>
    14821500 * </ol>
    14831501 *
     
    14861504 * define('WP_PROXY_HOST', '192.168.84.101');
    14871505 * define('WP_PROXY_PORT', '8080');
    1488  * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
     1506 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org');
    14891507 * </code>
    14901508 *
    14911509 * @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
    14921511 * @since 2.8
    14931512 */
     
    16061625     *
    16071626     * @uses WP_PROXY_BYPASS_HOSTS
    1608      * @since unknown
     1627     * @since 2.8.0
    16091628     *
    16101629     * @param string $uri URI to check.
     
    16291648
    16301649        static $bypass_hosts;
    1631         if ( null == $bypass_hosts )
     1650        static $wildcard_regex = false;
     1651        if ( null == $bypass_hosts ) {
    16321652            $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS);
    16331653
    1634         return !in_array( $check['host'], $bypass_hosts );
     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 );
    16351666    }
    16361667}
Note: See TracChangeset for help on using the changeset viewer.