WordPress.org

Make WordPress Core

Ticket #7770: 7770.3.diff

File 7770.3.diff, 4.4 KB (added by DD32, 5 years ago)

extra redirect code wasnt needed.

  • wp-includes/http.php

     
    530530                if ( (int) $arrHeaders['response']['code'] >= 400 && (int) $arrHeaders['response']['code'] < 500 ) 
    531531                        return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']); 
    532532 
    533                 // If the body was chunk encoded, then decode it. 
    534                 if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) 
    535                         $process['body'] = WP_Http::chunkTransferDecode($process['body']); 
    536  
    537533                // If location is found, then assume redirect and redirect to location. 
    538534                if ( isset($arrHeaders['headers']['location']) ) { 
    539535                        if ( $r['redirection']-- > 0 ) { 
    540536                                return $this->request($arrHeaders['headers']['location'], $r); 
     537                        } else { 
     538                                return new WP_Error('http_request_failed', __('Too many redirects.')); 
    541539                        } 
    542                         else 
    543                                 return new WP_Error('http_request_failed', __('Too many redirects.')); 
    544540                } 
    545541 
     542                // If the body was chunk encoded, then decode it. 
     543                if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) 
     544                        $process['body'] = WP_Http::chunkTransferDecode($process['body']); 
     545 
    546546                return array('headers' => $arrHeaders['headers'], 'body' => $process['body'], 'response' => $arrHeaders['response']); 
    547547        } 
    548548 
     
    858858                        'headers' => $r['headers'], 
    859859                ); 
    860860 
    861                 $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); 
     861                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) //Emits warning level notices for max redirects and timeouts 
     862                        $strResponse = @http_request($r['method'], $url, $r['body'], $options, $info); 
     863                else 
     864                        $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); //Emits warning level notices for max redirects and timeouts 
    862865 
    863                 if ( false === $strResponse ) 
     866                if ( false === $strResponse || ! empty($info['error']) ) //Error may still be set, Response may return headers or partial document, and error contains a reason the request was aborted, eg, timeout expired or max-redirects reached 
    864867                        return new WP_Error('http_request_failed', $info['response_code'] . ': ' . $info['error']); 
    865868 
    866869                if ( ! $r['blocking'] ) 
     
    869872                list($theHeaders, $theBody) = explode("\r\n\r\n", $strResponse, 2); 
    870873                $theHeaders = WP_Http::processHeaders($theHeaders); 
    871874 
    872                 if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) 
    873                         $theBody = http_chunked_decode($theBody); 
     875                if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) { 
     876                        if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) 
     877                                $theBody = @http_chunked_decode($theBody); 
     878                        else 
     879                                $theBody = http_chunked_decode($theBody); 
     880                } 
    874881 
    875882                $theResponse = array(); 
    876883                $theResponse['code'] = $info['response_code']; 
     
    970977 
    971978                $theResponse = curl_exec( $handle ); 
    972979 
    973                 list($theHeaders, $theBody) = explode("\r\n\r\n", $theResponse, 2); 
    974                 $theHeaders = WP_Http::processHeaders($theHeaders); 
    975  
    976                 if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) 
    977                         $theBody = WP_Http::chunkTransferDecode($theBody); 
    978  
     980                if ( $theResponse ) { 
     981                        $headerLength = curl_getinfo($handle, CURLINFO_HEADER_SIZE); 
     982                        $theHeaders = trim( substr($theResponse, 0, $headerLength) ); 
     983                        $theBody = substr( $theResponse, $headerLength ); 
     984                        if ( false !== strrpos($theHeaders, "\r\n\r\n") ) { 
     985                                $headerParts = explode("\r\n\r\n", $theHeaders); 
     986                                $theHeaders = $headerParts[ count($headerParts) -1 ]; 
     987                        } 
     988                        $theHeaders = WP_Http::processHeaders($theHeaders); 
     989                } else { 
     990                        if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array(301, 302) ) ) 
     991                                return new WP_Error('http_request_failed', __('Too many redirects.')); 
     992                        $theHeaders = array( 'headers' => array() ); 
     993                        $theBody = ''; 
     994                } 
    979995                $response = array(); 
    980996                $response['code'] = curl_getinfo( $handle, CURLINFO_HTTP_CODE ); 
    981997                $response['message'] = get_status_header_desc($response['code']);