Make WordPress Core

Changeset 13149


Ignore:
Timestamp:
02/14/2010 10:41:07 AM (16 years ago)
Author:
dd32
Message:

Disable Redirection on HEAD requests. See #10624

File:
1 edited

Legend:

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

    r12785 r13149  
    749749
    750750        // If location is found, then assume redirect and redirect to location.
    751         if ( isset($arrHeaders['headers']['location']) ) {
     751        if ( 'HEAD' != $r['method'] && isset($arrHeaders['headers']['location']) ) {
    752752            if ( $r['redirection']-- > 0 ) {
    753753                return $this->request($arrHeaders['headers']['location'], $r);
     
    916916            return false;
    917917
     918        if ( isset($args['method']) && 'HEAD' == $args['method'] ) //This transport cannot make a HEAD request
     919            return false;
     920
    918921        $use = true;
    919 
    920922        //PHP does not verify SSL certs, We can only make a request via this transports if SSL Verification is turned off.
    921923        $is_ssl = isset($args['ssl']) && $args['ssl'];
     
    10111013                'protocol_version' => (float) $r['httpversion'],
    10121014                'header' => $strHeaders,
     1015                'ignore_errors' => true, // Return non-200 requests.
    10131016                'timeout' => $r['timeout'],
    10141017                'ssl' => array(
     
    10301033        }
    10311034
    1032         if ( ! is_null($r['body']) && ! empty($r['body'] ) )
     1035        if ( 'HEAD' == $r['method'] ) // Disable redirects for HEAD requests
     1036            $arrContext['http']['max_redirects'] = 1;
     1037
     1038        if ( ! empty($r['body'] ) )
    10331039            $arrContext['http']['content'] = $r['body'];
    10341040
     
    10401046            $handle = fopen($url, 'r', false, $context);
    10411047
    1042         if ( ! $handle)
     1048        if ( ! $handle )
    10431049            return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
    10441050
     
    11911197        );
    11921198
     1199        if ( HTTP_METH_HEAD == $r['method'] )
     1200            $options['redirect'] = 0; // Assumption: Docs seem to suggest that this means do not follow. Untested.
     1201
    11931202        // The HTTP extensions offers really easy proxy support.
    11941203        $proxy = new WP_HTTP_Proxy();
     
    13591368
    13601369        // The option doesn't work with safe mode or when open_basedir is set.
    1361         if ( !ini_get('safe_mode') && !ini_get('open_basedir') )
     1370        // Disable HEAD when making HEAD requests.
     1371        if ( !ini_get('safe_mode') && !ini_get('open_basedir') && 'HEAD' != $r['method'] )
    13621372            curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
    13631373
Note: See TracChangeset for help on using the changeset viewer.