Make WordPress Core

Ticket #20219: class-http.php.2.diff

File class-http.php.2.diff, 2.7 KB (added by Workshopshed, 13 years ago)

Explicitly set an "autoredirect" flag

  • C:/Users/andyc/Documents/My

     
    10421042                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, ( $ssl_verify === true ) ? 2 : false );
    10431043                curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
    10441044                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    1045                 curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
    10461045
    10471046                switch ( $r['method'] ) {
    10481047                        case 'HEAD':
     
    10741073                        curl_setopt( $handle, CURLOPT_FILE, $stream_handle );
    10751074                }
    10761075
    1077                 // The option doesn't work with safe mode or when open_basedir is set.
     1076                // The curl follow location option doesn't work with safe mode or when open_basedir is set.
    10781077                if ( !ini_get('safe_mode') && !ini_get('open_basedir') && 0 !== $r['_redirection'] )
    1079                         curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
     1078            $autoredirect = true;
     1079       
     1080        if ($autoredirect)   {
     1081            curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
     1082            curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
     1083        }
    10801084
    10811085                if ( !empty( $r['headers'] ) ) {
    10821086                        // cURL expects full header strings in each element
     
    11101114                if ( strlen($theResponse) > 0 && ! is_bool( $theResponse ) ) // is_bool: when using $args['stream'], curl_exec will return (bool)true
    11111115                        $theBody = $theResponse;
    11121116
    1113                 // If no response, and It's not a HEAD request with valid headers returned
    1114                 if ( 0 == strlen($theResponse) && ('HEAD' != $args['method'] || empty($this->headers)) ) {
    1115                         if ( $curl_error = curl_error($handle) )
    1116                                 return new WP_Error('http_request_failed', $curl_error);
     1117        if ( $curl_error = curl_error($handle) )
     1118                        return new WP_Error('http_request_failed', $curl_error);
     1119
     1120                // Handle too many redirects with Curl auto redirect
     1121                if ($autoredirect && 0 == strlen($theResponse) && ('HEAD' != $args['method'] || empty($this->headers)) ) {
    11171122                        if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array(301, 302) ) )
    11181123                    return new WP_Error('http_request_failed', __('Too many redirects.'));
    11191124                }
     
    11301135                        fclose( $stream_handle );
    11311136
    11321137                // See #11305 - When running under safe mode, redirection is disabled above. Handle it manually.
    1133                 if ( ! empty( $theHeaders['headers']['location'] ) && ( ini_get( 'safe_mode' ) || ini_get( 'open_basedir' ) ) && 0 !== $r['_redirection'] ) {
     1138                if ( ! empty( $theHeaders['headers']['location'] ) && !$autoredirect ) {
    11341139                        if ( $r['redirection']-- > 0 ) {
    11351140                                return $this->request( $theHeaders['headers']['location'], $r );
    11361141                        } else {