WordPress.org

Make WordPress Core

Changeset 8634


Ignore:
Timestamp:
08/13/08 05:09:59 (7 years ago)
Author:
westi
Message:

Fix bugs in chunked encoding handling. See #4779 props santosj.

File:
1 edited

Legend:

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

    r8630 r8634  
    352352     * 
    353353     * @todo Add support for footer chunked headers. 
    354      * 
     354     * @access public 
     355     * @since 2.7 
    355356     * @static 
     357     * 
    356358     * @param string $body Body content 
    357359     * @return bool|string|WP_Error False if not chunked encoded. WP_Error on failure. Chunked decoded body on success. 
     
    363365            return false; 
    364366 
    365         $hex = ''; 
    366         $dec = 0; 
    367367        $parsedBody = ''; 
    368         $parsedHeaders = array(); 
     368        //$parsedHeaders = array(); Unsupported 
    369369 
    370370        $done = false; 
     
    381381                $chunkLength = strlen( $match[0] ); 
    382382 
    383                 if( $body{$length+$chunkLength} == "\n" ) 
    384                     $length++; 
    385  
    386383                $strBody = substr($body, strlen( $match[0] ), $length); 
    387384                $parsedBody .= $strBody; 
    388                 $body = str_replace(array($match[0], $strBody), '', $body); 
    389  
    390                 if( "0" == $body ) { 
     385 
     386                $body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n"); 
     387 
     388                if( "0" == trim($body) ) { 
    391389                    $done = true; 
    392390                    return $parsedBody; // Ignore footer headers. 
     
    512510        $arrHeaders = WP_Http::processHeaders($process['headers']); 
    513511 
    514         if ( WP_Http_Fsockopen::is400Response($arrHeaders['response']['code']) ) 
     512        // Is the response code within the 400 range? 
     513        if ( (int) $arrHeaders['response']['code'] >= 400 && (int) $arrHeaders['response']['code'] < 500 ) 
    515514            return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']); 
     515 
     516        // If the body was chunk encoded, then decode it. 
     517        if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) 
     518            $process['body'] = WP_Http::chunkTransferDecode($process['body']); 
    516519 
    517520        // If location is found, then assume redirect and redirect to location. 
     
    540543        return false; 
    541544    } 
    542  
    543     /** 
    544      * Whether response code is in the 400 range. 
    545      * 
    546      * @access public 
    547      * @static 
    548      * @since 2.7 
    549      * 
    550      * @param string $response Response code. 
    551      * @return bool True if 40x Response, false if something else. 
    552      */ 
    553     function is400Response($response) { 
    554         if ( is_numeric($response) && (int) substr($response, 0, 1) == 4 ) 
    555             return true; 
    556         return false; 
    557     } 
    558545} 
    559546 
     
    640627 
    641628        if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 
    642             $theBody = WP_Http::chunkTransferDecode($strResponse); 
     629            $strResponse = WP_Http::chunkTransferDecode($strResponse); 
    643630 
    644631        return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response']); 
     
    752739 
    753740        if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 
    754             $theBody = WP_Http::chunkTransferDecode($strResponse); 
     741            $strResponse = WP_Http::chunkTransferDecode($strResponse); 
    755742 
    756743        fclose($handle); 
Note: See TracChangeset for help on using the changeset viewer.