WordPress.org

Make WordPress Core

Changeset 9091


Ignore:
Timestamp:
10/06/2008 11:10:22 PM (13 years ago)
Author:
ryan
Message:

Chunked encoding fixes from DD32. fixes #7770

File:
1 edited

Legend:

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

    r8842 r9091  
    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.'));
    544         }
     540        }
     541
     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']);
    545545
    546546        return array('headers' => $arrHeaders['headers'], 'body' => $process['body'], 'response' => $arrHeaders['response']);
     
    859859        );
    860860
    861         $strResponse = http_request($r['method'], $url, $r['body'], $options, $info);
    862 
    863         if ( false === $strResponse )
     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
     865
     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
     
    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();
     
    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 );
Note: See TracChangeset for help on using the changeset viewer.