Ticket #4779: 4779.r8630.diff
File 4779.r8630.diff, 3.5 KB (added by , 16 years ago) |
---|
-
http.php
351 351 * difficult to support it though. 352 352 * 353 353 * @todo Add support for footer chunked headers. 354 * 354 * @access public 355 * @since 2.7 355 356 * @static 357 * 356 358 * @param string $body Body content 357 359 * @return bool|string|WP_Error False if not chunked encoded. WP_Error on failure. Chunked decoded body on success. 358 360 */ … … 362 364 if ( ! preg_match( '/^[0-9a-f]+(\s|\n)+/mi', trim($body) ) ) 363 365 return false; 364 366 365 $hex = '';366 $dec = 0;367 367 $parsedBody = ''; 368 $parsedHeaders = array();368 //$parsedHeaders = array(); Unsupported 369 369 370 370 $done = false; 371 371 … … 380 380 $length = hexdec( $match[1] ); 381 381 $chunkLength = strlen( $match[0] ); 382 382 383 if( $body{$length+$chunkLength} == "\n" )384 $length++;385 386 383 $strBody = substr($body, strlen( $match[0] ), $length); 387 384 $parsedBody .= $strBody; 388 $body = str_replace(array($match[0], $strBody), '', $body);389 385 390 if( "0" == $body ) { 386 $body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n"); 387 388 if( "0" == trim($body) ) { 391 389 $done = true; 392 390 return $parsedBody; // Ignore footer headers. 393 391 break; … … 511 509 $process = WP_Http::processResponse($strResponse); 512 510 $arrHeaders = WP_Http::processHeaders($process['headers']); 513 511 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 ) 515 514 return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']); 516 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']); 519 517 520 // If location is found, then assume redirect and redirect to location. 518 521 if ( isset($arrHeaders['headers']['location']) ) { 519 522 if ( $r['redirection']-- > 0 ) { … … 539 542 540 543 return false; 541 544 } 542 543 /**544 * Whether response code is in the 400 range.545 *546 * @access public547 * @static548 * @since 2.7549 *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 }558 545 } 559 546 560 547 /** … … 639 626 $processedHeaders = WP_Http::processHeaders($theHeaders); 640 627 641 628 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); 643 630 644 631 return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response']); 645 632 } … … 751 738 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']); 752 739 753 740 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); 755 742 756 743 fclose($handle); 757 744