27 #require_once 'Zend/Http/Header/HeaderValue.php'; 50 101 =>
'Switching Protocols',
56 203 =>
'Non-Authoritative Information',
58 205 =>
'Reset Content',
59 206 =>
'Partial Content',
62 300 =>
'Multiple Choices',
63 301 =>
'Moved Permanently',
66 304 =>
'Not Modified',
69 307 =>
'Temporary Redirect',
73 401 =>
'Unauthorized',
74 402 =>
'Payment Required',
77 405 =>
'Method Not Allowed',
78 406 =>
'Not Acceptable',
79 407 =>
'Proxy Authentication Required',
80 408 =>
'Request Timeout',
83 411 =>
'Length Required',
84 412 =>
'Precondition Failed',
85 413 =>
'Request Entity Too Large',
86 414 =>
'Request-URI Too Long',
87 415 =>
'Unsupported Media Type',
88 416 =>
'Requested Range Not Satisfiable',
89 417 =>
'Expectation Failed',
92 500 =>
'Internal Server Error',
93 501 =>
'Not Implemented',
95 503 =>
'Service Unavailable',
96 504 =>
'Gateway Timeout',
97 505 =>
'HTTP Version Not Supported',
98 509 =>
'Bandwidth Limit Exceeded' 159 if (self::responseCodeAsText(
$code) ===
null) {
160 #require_once 'Zend/Http/Exception.php'; 168 $header = explode(
":",
$value, 2);
169 if (count($header) != 2) {
170 #require_once 'Zend/Http/Exception.php'; 174 $name = trim($header[0]);
175 $value = trim($header[1]);
178 $this->headers[ucwords(strtolower(
$name))] =
$value;
185 if (! preg_match(
'|^\d\.\d$|',
$version)) {
186 #require_once 'Zend/Http/Exception.php'; 208 $restype = floor($this->code / 100);
209 if ($restype == 4 || $restype == 5) {
223 $restype = floor($this->code / 100);
224 if ($restype == 2 || $restype == 1) {
238 $restype = floor($this->code / 100);
263 switch (strtolower($this->
getHeader(
'transfer-encoding'))) {
278 switch (strtolower($this->
getHeader(
'content-encoding'))) {
359 $header = ucwords(strtolower($header));
360 if (! is_string($header) || ! isset($this->headers[$header]))
return null;
362 return $this->headers[$header];
377 $str =
"HTTP/{$this->version} {$this->code} {$this->message}{$br}";
384 $str .=
"{$name}: {$value}{$br}";
387 foreach (
$value as $subval) {
388 $str .=
"{$name}: {$subval}{$br}";
432 if (! $http11)
$messages[302] =
'Moved Temporarily';
434 if (
$code ===
null) {
451 preg_match(
"|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
468 preg_match(
"|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
485 preg_match(
"|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
506 $parts = preg_split(
'|(?:\r\n){2}|m', $response_str, 2);
512 $lines = explode(
"\r\n", $parts[0]);
516 foreach($lines as
$index => $line) {
517 if (
$index === 0 && preg_match(
'#^HTTP/\d+(?:\.\d+) [1-5]\d+#', $line)) {
528 if (preg_match(
"|^([a-zA-Z0-9\'`#$%&*+.^_\|\~!-]+):\s*(.*)|s", $line, $m)) {
530 $h_name = strtolower($m[1]);
535 if (! is_array(
$headers[$h_name])) {
539 $headers[$h_name][] = ltrim($h_value);
540 $last_header = $h_name;
544 $headers[$h_name] = ltrim($h_value);
545 $last_header = $h_name;
550 if (preg_match(
"|^[ \t](.+)$|s", $line, $m) && $last_header !==
null) {
551 $h_value = trim($m[1]);
552 if (is_array(
$headers[$last_header])) {
554 $last_header_key = key(
$headers[$last_header]);
556 $h_value =
$headers[$last_header][$last_header_key] . $h_value;
559 $headers[$last_header][$last_header_key] = $h_value;
563 $h_value =
$headers[$last_header] . $h_value;
571 #require_once 'Zend/Http/Exception.php'; 586 $parts = preg_split(
'|(?:\r\n){2}|m', $response_str, 2);
587 if (isset($parts[1])) {
606 ((
int)
ini_get(
'mbstring.func_overload')) & 2) {
608 $mbIntEnc = mb_internal_encoding();
609 mb_internal_encoding(
'ASCII');
612 while (trim(
$body)) {
613 if (! preg_match(
"/^([\da-fA-F]+)[^\r\n]*\r\n/sm",
$body, $m)) {
614 #require_once 'Zend/Http/Exception.php'; 615 throw new Zend_Http_Exception(
"Error parsing body - doesn't seem to be a chunked message");
618 $length = hexdec(trim($m[1]));
619 $cut = strlen($m[0]);
620 $decBody .= substr(
$body, $cut, $length);
624 if (isset($mbIntEnc)) {
625 mb_internal_encoding($mbIntEnc);
642 #require_once 'Zend/Http/Exception.php'; 644 'zlib extension is required in order to decode "gzip" encoding' 648 return gzinflate(substr(
$body, 10));
662 #require_once 'Zend/Http/Exception.php'; 664 'zlib extension is required in order to decode "deflate" encoding' 679 $zlibHeader = unpack(
'n', substr(
$body, 0, 2));
680 if ($zlibHeader[1] % 31 == 0 && ord(
$body[0]) == 0x78 && in_array(ord(
$body[1]), array(0x01, 0x5e, 0x9c, 0xda))) {
681 return gzuncompress(
$body);
683 return gzinflate(
$body);
static extractHeaders($response_str)
elseif(isset( $params[ 'redirect_parent']))
static extractVersion($response_str)
static fromString($response_str)
getHeadersAsString($status_line=true, $br="\n")
static decodeChunkedBody($body)
static extractBody($response_str)
static extractMessage($response_str)
__construct($code, array $headers, $body=null, $version='1.1', $message=null)
static decodeDeflate($body)
static extractCode($response_str)
static responseCodeAsText($code=null, $http11=true)
if(!isset($_GET['name'])) $name