import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -16,8 +16,8 @@
|
||||
* @category Zend
|
||||
* @package Zend_Http
|
||||
* @subpackage Response
|
||||
* @version $Id: Response.php 16024 2009-06-12 15:44:56Z doctorrock83 $
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Response.php 17124 2009-07-26 09:46:42Z shahar $
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
*
|
||||
* @package Zend_Http
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Http_Response
|
||||
@ -253,7 +253,7 @@ class Zend_Http_Response
|
||||
$body = '';
|
||||
|
||||
// Decode the body if it was transfer-encoded
|
||||
switch ($this->getHeader('transfer-encoding')) {
|
||||
switch (strtolower($this->getHeader('transfer-encoding'))) {
|
||||
|
||||
// Handle chunked body
|
||||
case 'chunked':
|
||||
@ -493,11 +493,11 @@ class Zend_Http_Response
|
||||
public static function extractHeaders($response_str)
|
||||
{
|
||||
$headers = array();
|
||||
|
||||
|
||||
// First, split body and headers
|
||||
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
||||
if (! $parts[0]) return $headers;
|
||||
|
||||
|
||||
// Split headers part to lines
|
||||
$lines = explode("\n", $parts[0]);
|
||||
unset($parts);
|
||||
@ -545,7 +545,7 @@ class Zend_Http_Response
|
||||
public static function extractBody($response_str)
|
||||
{
|
||||
$parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
|
||||
if (isset($parts[1])) {
|
||||
if (isset($parts[1])) {
|
||||
return $parts[1];
|
||||
}
|
||||
return '';
|
||||
@ -560,7 +560,16 @@ class Zend_Http_Response
|
||||
public static function decodeChunkedBody($body)
|
||||
{
|
||||
$decBody = '';
|
||||
|
||||
|
||||
// If mbstring overloads substr and strlen functions, we have to
|
||||
// override it's internal encoding
|
||||
if (function_exists('mb_internal_encoding') &&
|
||||
((int) ini_get('mbstring.func_overload')) & 2) {
|
||||
|
||||
$mbIntEnc = mb_internal_encoding();
|
||||
mb_internal_encoding('ASCII');
|
||||
}
|
||||
|
||||
while (trim($body)) {
|
||||
if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
@ -569,11 +578,14 @@ class Zend_Http_Response
|
||||
|
||||
$length = hexdec(trim($m[1]));
|
||||
$cut = strlen($m[0]);
|
||||
|
||||
$decBody .= substr($body, $cut, $length);
|
||||
$body = substr($body, $cut + $length + 2);
|
||||
}
|
||||
|
||||
if (isset($mbIntEnc)) {
|
||||
mb_internal_encoding($mbIntEnc);
|
||||
}
|
||||
|
||||
return $decBody;
|
||||
}
|
||||
|
||||
@ -589,8 +601,9 @@ class Zend_Http_Response
|
||||
{
|
||||
if (! function_exists('gzinflate')) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
throw new Zend_Http_Exception('Unable to decode gzipped response ' .
|
||||
'body: perhaps the zlib extension is not loaded?');
|
||||
throw new Zend_Http_Exception(
|
||||
'zlib extension is required in order to decode "gzip" encoding'
|
||||
);
|
||||
}
|
||||
|
||||
return gzinflate(substr($body, 10));
|
||||
@ -608,11 +621,28 @@ class Zend_Http_Response
|
||||
{
|
||||
if (! function_exists('gzuncompress')) {
|
||||
require_once 'Zend/Http/Exception.php';
|
||||
throw new Zend_Http_Exception('Unable to decode deflated response ' .
|
||||
'body: perhaps the zlib extension is not loaded?');
|
||||
throw new Zend_Http_Exception(
|
||||
'zlib extension is required in order to decode "deflate" encoding'
|
||||
);
|
||||
}
|
||||
|
||||
return gzuncompress($body);
|
||||
/**
|
||||
* Some servers (IIS ?) send a broken deflate response, without the
|
||||
* RFC-required zlib header.
|
||||
*
|
||||
* We try to detect the zlib header, and if it does not exsit we
|
||||
* teat the body is plain DEFLATE content.
|
||||
*
|
||||
* This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
|
||||
*
|
||||
* @link http://framework.zend.com/issues/browse/ZF-6040
|
||||
*/
|
||||
$zlibHeader = unpack('n', substr($body, 0, 2));
|
||||
if ($zlibHeader[1] % 31 == 0) {
|
||||
return gzuncompress($body);
|
||||
} else {
|
||||
return gzinflate($body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user