52 require_once
'PEAR.php';
56 require_once
'Net/Socket.php';
60 require_once
'Net/URL.php';
65 define(
'HTTP_REQUEST_METHOD_GET',
'GET',
true);
66 define(
'HTTP_REQUEST_METHOD_HEAD',
'HEAD',
true);
67 define(
'HTTP_REQUEST_METHOD_POST',
'POST',
true);
68 define(
'HTTP_REQUEST_METHOD_PUT',
'PUT',
true);
69 define(
'HTTP_REQUEST_METHOD_DELETE',
'DELETE',
true);
70 define(
'HTTP_REQUEST_METHOD_OPTIONS',
'OPTIONS',
true);
71 define(
'HTTP_REQUEST_METHOD_TRACE',
'TRACE',
true);
77 define(
'HTTP_REQUEST_ERROR_FILE', 1);
78 define(
'HTTP_REQUEST_ERROR_URL', 2);
79 define(
'HTTP_REQUEST_ERROR_PROXY', 4);
80 define(
'HTTP_REQUEST_ERROR_REDIRECTS', 8);
81 define(
'HTTP_REQUEST_ERROR_RESPONSE', 16);
82 define(
'HTTP_REQUEST_ERROR_GZIP_METHOD', 32);
83 define(
'HTTP_REQUEST_ERROR_GZIP_READ', 64);
84 define(
'HTTP_REQUEST_ERROR_GZIP_DATA', 128);
85 define(
'HTTP_REQUEST_ERROR_GZIP_CRC', 256);
91 define(
'HTTP_REQUEST_HTTP_VER_1_0',
'1.0',
true);
92 define(
'HTTP_REQUEST_HTTP_VER_1_1',
'1.1',
true);
95 if (extension_loaded(
'mbstring') && (2 & ini_get(
'mbstring.func_overload'))) {
99 define(
'HTTP_REQUEST_MBSTRING',
true);
104 define(
'HTTP_REQUEST_MBSTRING',
false);
150 var $_requestHeaders;
210 var $_bodyDisallowed = array(
'TRACE');
220 var $_bodyRequired = array(
'POST',
'PUT');
226 var $_postFiles = array();
244 var $_allowRedirects;
262 var $_useBrackets =
true;
268 var $_listeners = array();
274 var $_saveBody =
true;
280 var $_readTimeout = null;
286 var $_socketOptions = null;
316 $this->_method = HTTP_REQUEST_METHOD_GET;
317 $this->_http = HTTP_REQUEST_HTTP_VER_1_1;
318 $this->_requestHeaders = array();
319 $this->_postData = array();
325 $this->_proxy_host = null;
326 $this->_proxy_port = null;
327 $this->_proxy_user = null;
328 $this->_proxy_pass = null;
330 $this->_allowRedirects =
false;
331 $this->_maxRedirects = 3;
332 $this->_redirects = 0;
334 $this->_timeout = null;
335 $this->_response = null;
337 foreach ($params as $key => $value) {
338 $this->{
'_' . $key} = $value;
346 $this->
addHeader(
'User-Agent',
'PEAR HTTP_Request class ( http://pear.php.net/ )');
352 if (!empty($this->_user)) {
353 $this->
addHeader(
'Authorization',
'Basic ' . base64_encode($this->_user .
':' . $this->_pass));
357 if (!empty($this->_proxy_user)) {
358 $this->
addHeader(
'Proxy-Authorization',
'Basic ' . base64_encode($this->_proxy_user .
':' . $this->_proxy_pass));
362 if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded(
'zlib')) {
363 $this->
addHeader(
'Accept-Encoding',
'gzip');
375 if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol,
'http') == 0) {
376 $host = $this->_url->host .
':' . $this->_url->port;
378 } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol,
'https') == 0) {
379 $host = $this->_url->host .
':' . $this->_url->port;
381 } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol,
'https') == 0 AND strpos($this->_url->url,
':443') !==
false) {
382 $host = $this->_url->host .
':' . $this->_url->port;
385 $host = $this->_url->host;
401 function reset($url, $params = array())
414 $this->_url =
new Net_URL($url, $this->_useBrackets);
416 if (!empty($this->_url->user) || !empty($this->_url->pass)) {
417 $this->
setBasicAuth($this->_url->user, $this->_url->pass);
420 if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) {
425 if (empty($this->_url->path)) {
426 $this->_url->path =
'/';
438 return empty($this->_url)?
'': $this->_url->getUrl();
450 function setProxy($host, $port = 8080, $user = null, $pass = null)
452 $this->_proxy_host = $host;
453 $this->_proxy_port = $port;
454 $this->_proxy_user = $user;
455 $this->_proxy_pass = $pass;
458 $this->
addHeader(
'Proxy-Authorization',
'Basic ' . base64_encode($user .
':' . $pass));
470 $this->_user = $user;
471 $this->_pass = $pass;
473 $this->
addHeader(
'Authorization',
'Basic ' . base64_encode($user .
':' . $pass));
484 $this->_method = $method;
495 $this->_http = $http;
507 $this->_requestHeaders[strtolower($name)] = $value;
518 if (isset($this->_requestHeaders[strtolower($name)])) {
519 unset($this->_requestHeaders[strtolower($name)]);
533 $this->_url->addQueryString($name, $value, $preencoded);
545 $this->_url->addRawQueryString($querystring, $preencoded);
559 $this->_postData[$name] = $value;
575 if (!is_array($value)) {
576 return call_user_func($callback, $value);
579 foreach ($value as $k => $v) {
602 function addFile($inputName, $fileName, $contentType =
'application/octet-stream')
604 if (!is_array($fileName) && !is_readable($fileName)) {
605 return PEAR::raiseError(
"File '{$fileName}' is not readable", HTTP_REQUEST_ERROR_FILE);
606 } elseif (is_array($fileName)) {
607 foreach ($fileName as $name) {
608 if (!is_readable($name)) {
609 return PEAR::raiseError(
"File '{$name}' is not readable", HTTP_REQUEST_ERROR_FILE);
613 $this->
addHeader(
'Content-Type',
'multipart/form-data');
614 $this->_postFiles[$inputName] = array(
616 'type' => $contentType
631 $this->_body = $preencoded ? $postdata : urlencode($postdata);
642 $this->_body = $body;
655 $this->_postData = null;
667 $cookies = isset($this->_requestHeaders[
'cookie']) ? $this->_requestHeaders[
'cookie'].
'; ' :
'';
668 $this->
addHeader(
'Cookie', $cookies . $name .
'=' . $value);
694 if (!is_a($this->_url,
'Net_URL')) {
695 return PEAR::raiseError(
'No URL given', HTTP_REQUEST_ERROR_URL);
698 $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host;
699 $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port;
701 if (strcasecmp($this->_url->protocol,
'https') == 0) {
703 if (version_compare(PHP_VERSION,
'4.3.0',
'<') || !extension_loaded(
'openssl')) {
704 return PEAR::raiseError(
'Need PHP 4.3.0 or later with OpenSSL support for https:// requests',
705 HTTP_REQUEST_ERROR_URL);
706 } elseif (isset($this->_proxy_host)) {
707 return PEAR::raiseError(
'HTTPS proxies are not supported', HTTP_REQUEST_ERROR_PROXY);
709 $host =
'ssl://' . $host;
713 $magicQuotes = ini_get(
'magic_quotes_runtime');
714 ini_set(
'magic_quotes_runtime',
false);
718 if (isset($this->_proxy_host) && !empty($this->_requestHeaders[
'connection']) &&
719 'Keep-Alive' == $this->_requestHeaders[
'connection'])
724 $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders[
'connection'])) ||
725 (!empty($this->_requestHeaders[
'connection']) &&
'Keep-Alive' == $this->_requestHeaders[
'connection']);
726 $sockets = &PEAR::getStaticProperty(
'HTTP_Request',
'sockets');
727 $sockKey = $host .
':' . $port;
731 if ($keepAlive && !empty($sockets[$sockKey]) &&
732 !empty($sockets[$sockKey]->fp))
734 $this->_sock =& $sockets[$sockKey];
738 $this->_sock =
new Net_Socket();
739 $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions);
741 PEAR::isError($err) or $err = $this->_sock->write($this->
_buildRequest());
743 if (!PEAR::isError($err)) {
744 if (!empty($this->_readTimeout)) {
745 $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]);
751 $this->_response =
new HTTP_Response($this->_sock, $this->_listeners);
752 $err = $this->_response->process(
753 $this->_saveBody && $saveBody,
754 HTTP_REQUEST_METHOD_HEAD != $this->_method
758 $keepAlive = (isset($this->_response->_headers[
'content-length'])
759 || (isset($this->_response->_headers[
'transfer-encoding'])
760 && strtolower($this->_response->_headers[
'transfer-encoding']) ==
'chunked'));
762 if (isset($this->_response->_headers[
'connection'])) {
763 $keepAlive = strtolower($this->_response->_headers[
'connection']) ==
'keep-alive';
765 $keepAlive =
'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol;
771 ini_set(
'magic_quotes_runtime', $magicQuotes);
773 if (PEAR::isError($err)) {
780 } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) {
781 $sockets[$sockKey] =& $this->_sock;
785 if ( $this->_allowRedirects
786 AND $this->_redirects <= $this->_maxRedirects
789 AND !empty($this->_response->_headers[
'location'])) {
792 $redirect = $this->_response->_headers[
'location'];
795 if (preg_match(
'/^https?:\/\//i', $redirect)) {
796 $this->_url =
new Net_URL($redirect);
799 } elseif ($redirect{0} ==
'/') {
800 $this->_url->path = $redirect;
803 } elseif (substr($redirect, 0, 3) ==
'../' OR substr($redirect, 0, 2) ==
'./') {
804 if (substr($this->_url->path, -1) ==
'/') {
805 $redirect = $this->_url->path . $redirect;
807 $redirect = dirname($this->_url->path) .
'/' . $redirect;
809 $redirect = Net_URL::resolvePath($redirect);
810 $this->_url->path = $redirect;
814 if (substr($this->_url->path, -1) ==
'/') {
815 $redirect = $this->_url->path . $redirect;
817 $redirect = dirname($this->_url->path) .
'/' . $redirect;
819 $this->_url->path = $redirect;
826 } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) {
827 return PEAR::raiseError(
'Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS);
840 if (!empty($this->_sock) && !empty($this->_sock->fp)) {
842 $this->_sock->disconnect();
854 return isset($this->_response->_code) ? $this->_response->_code :
false;
865 return isset($this->_response->_reason) ? $this->_response->_reason :
false;
878 if (!isset($headername)) {
879 return isset($this->_response->_headers)? $this->_response->_headers: array();
881 $headername = strtolower($headername);
882 return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] :
false;
894 return isset($this->_response->_body) ? $this->_response->_body :
false;
905 return isset($this->_response->_cookies) ? $this->_response->_cookies :
false;
928 if (strlen($this->_url->path) > 1 && substr($this->_url->path, -1) ==
'/') {
932 $path_parts = preg_split(
'|/|', $this->_url->path, -1, PREG_SPLIT_NO_EMPTY);
934 if (empty($path_parts)) {
938 foreach ($path_parts as $key => $part) {
940 if (preg_match(
'/%[^a-f0-9]/i', $part) || preg_match(
'/[^@a-z0-9_.!~*\'()$+&,:=-]/i', $part)) {
941 $path_parts[$key] = urlencode(urldecode($part));
945 $path =
'/'.implode(
'/', $path_parts);
962 $separator = ini_get(
'arg_separator.output');
963 ini_set(
'arg_separator.output',
'&');
964 $querystring = ($querystring = $this->_url->getQueryString()) ?
'?' . $querystring :
'';
965 ini_set(
'arg_separator.output', $separator);
967 $host = isset($this->_proxy_host) ? $this->_url->protocol .
'://' . $this->_url->host :
'';
968 $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ?
':' . $this->_url->port :
'';
969 $path = $this->getEncodedPath() . $querystring;
970 $url = $host . $port . $path;
976 $request = $this->_method .
' ' . $url .
' HTTP/' . $this->_http .
"\r\n";
978 if (in_array($this->_method, $this->_bodyDisallowed) ||
979 (0 == strlen($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method ||
980 (empty($this->_postData) && empty($this->_postFiles)))))
984 if (empty($this->_requestHeaders[
'content-type'])) {
986 $this->
addHeader(
'Content-Type',
'application/x-www-form-urlencoded');
987 } elseif (
'multipart/form-data' == $this->_requestHeaders[
'content-type']) {
988 $boundary =
'HTTP_Request_' . md5(uniqid(
'request') . microtime());
989 $this->
addHeader(
'Content-Type',
'multipart/form-data; boundary=' . $boundary);
994 if (!empty($this->_requestHeaders)) {
995 foreach ($this->_requestHeaders as $name => $value) {
996 $canonicalName = implode(
'-', array_map(
'ucfirst', explode(
'-', $name)));
997 $request .= $canonicalName .
': ' . $value .
"\r\n";
1002 if (in_array($this->_method, $this->_bodyDisallowed)) {
1007 } elseif (HTTP_REQUEST_METHOD_POST == $this->_method &&
1008 (!empty($this->_postData) || !empty($this->_postFiles))) {
1011 if (!isset($boundary)) {
1012 $postdata = implode(
'&', array_map(
1013 create_function(
'$a',
'return $a[0] . \'=\' . $a[1];'),
1020 if (!empty($this->_postData)) {
1022 foreach ($flatData as $item) {
1023 $postdata .=
'--' . $boundary .
"\r\n";
1024 $postdata .=
'Content-Disposition: form-data; name="' . $item[0] .
'"';
1025 $postdata .=
"\r\n\r\n" . urldecode($item[1]) .
"\r\n";
1028 foreach ($this->_postFiles as $name => $value) {
1029 if (is_array($value[
'name'])) {
1030 $varname = $name . ($this->_useBrackets?
'[]':
'');
1033 $value[
'name'] = array($value[
'name']);
1035 foreach ($value[
'name'] as $key => $filename) {
1036 $fp = fopen($filename,
'r');
1037 $basename = basename($filename);
1038 $type = is_array($value[
'type'])? @$value[
'type'][$key]: $value[
'type'];
1040 $postdata .=
'--' . $boundary .
"\r\n";
1041 $postdata .=
'Content-Disposition: form-data; name="' . $varname .
'"; filename="' . $basename .
'"';
1042 $postdata .=
"\r\nContent-Type: " . $type;
1043 $postdata .=
"\r\n\r\n" . fread($fp, filesize($filename)) .
"\r\n";
1047 $postdata .=
'--' . $boundary .
"--\r\n";
1049 $request .=
'Content-Length: ' .
1050 (HTTP_REQUEST_MBSTRING? mb_strlen($postdata,
'iso-8859-1'): strlen($postdata)) .
1052 $request .= $postdata;
1055 } elseif (0 < strlen($this->_body)) {
1057 $request .=
'Content-Length: ' .
1058 (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body,
'iso-8859-1'): strlen($this->_body)) .
1060 $request .= $this->_body;
1066 if (in_array($this->_method, $this->_bodyRequired)) {
1067 $request .=
"Content-Length: 0\r\n";
1086 if (!is_array($values)) {
1087 return array(array($name, $values));
1090 foreach ($values as $k => $v) {
1093 } elseif ($this->_useBrackets) {
1094 $newName = $name .
'[' . $k .
']';
1098 $ret = array_merge($ret, $this->
_flattenArray($newName, $v));
1126 if (!is_a($listener,
'HTTP_Request_Listener')) {
1129 $this->_listeners[$listener->getId()] =& $listener;
1143 if (!is_a($listener,
'HTTP_Request_Listener') ||
1144 !isset($this->_listeners[$listener->getId()])) {
1147 unset($this->_listeners[$listener->getId()]);
1162 foreach (array_keys($this->_listeners) as $id) {
1163 $this->_listeners[$id]->update($this, $event, $data);
1226 var $_chunkLength = 0;
1232 var $_listeners = array();
1248 $this->_sock =& $sock;
1249 $this->_listeners =& $listeners;
1268 function process($saveBody =
true, $canHaveBody =
true)
1271 $line = $this->_sock->readLine();
1272 if (!preg_match(
'!^(HTTP/\d\.\d) (\d{3})(?: (.+))?!', $line, $s)) {
1273 return PEAR::raiseError(
'Malformed response', HTTP_REQUEST_ERROR_RESPONSE);
1275 $this->_protocol = $s[1];
1276 $this->_code = intval($s[2]);
1277 $this->_reason = empty($s[3])? null: $s[3];
1279 while (
'' !== ($header = $this->_sock->readLine())) {
1282 }
while (100 == $this->_code);
1284 $this->
_notify(
'gotHeaders', $this->_headers);
1292 $canHaveBody = $canHaveBody && $this->_code >= 200 &&
1293 $this->_code != 204 && $this->_code != 304;
1296 $chunked = isset($this->_headers[
'transfer-encoding']) && (
'chunked' == $this->_headers[
'transfer-encoding']);
1297 $gzipped = isset($this->_headers[
'content-encoding']) && (
'gzip' == $this->_headers[
'content-encoding']);
1299 if ($canHaveBody && ($chunked || !isset($this->_headers[
'content-length']) ||
1300 0 != $this->_headers[
'content-length']))
1302 if ($chunked || !isset($this->_headers[
'content-length'])) {
1303 $this->_toRead = null;
1305 $this->_toRead = $this->_headers[
'content-length'];
1307 while (!$this->_sock->eof() && (is_null($this->_toRead) || 0 < $this->_toRead)) {
1310 } elseif (is_null($this->_toRead)) {
1311 $data = $this->_sock->read(4096);
1313 $data = $this->_sock->read(min(4096, $this->_toRead));
1314 $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data,
'iso-8859-1'): strlen($data);
1316 if (
'' == $data && (!$this->_chunkLength || $this->_sock->eof())) {
1320 if ($saveBody || $gzipped) {
1321 $this->_body .= $data;
1323 $this->
_notify($gzipped?
'gzTick':
'tick', $data);
1332 if (PEAR::isError($body)) {
1335 $this->_body = $body;
1336 $this->
_notify(
'gotBody', $this->_body);
1353 if (
false === strpos($header,
':')) {
1356 list($headername, $headervalue) = explode(
':', $header, 2);
1357 $headername = strtolower($headername);
1358 $headervalue = ltrim($headervalue);
1360 if (
'set-cookie' != $headername) {
1361 if (isset($this->_headers[$headername])) {
1362 $this->_headers[$headername] .=
',' . $headervalue;
1364 $this->_headers[$headername] = $headervalue;
1388 if (!strpos($headervalue,
';')) {
1389 $pos = strpos($headervalue,
'=');
1390 $cookie[
'name'] = trim(substr($headervalue, 0, $pos));
1391 $cookie[
'value'] = trim(substr($headervalue, $pos + 1));
1395 $elements = explode(
';', $headervalue);
1396 $pos = strpos($elements[0],
'=');
1397 $cookie[
'name'] = trim(substr($elements[0], 0, $pos));
1398 $cookie[
'value'] = trim(substr($elements[0], $pos + 1));
1400 for ($i = 1; $i < count($elements); $i++) {
1401 if (
false === strpos($elements[$i],
'=')) {
1402 $elName = trim($elements[$i]);
1405 list ($elName, $elValue) = array_map(
'trim', explode(
'=', $elements[$i]));
1407 $elName = strtolower($elName);
1408 if (
'secure' == $elName) {
1409 $cookie[
'secure'] =
true;
1410 } elseif (
'expires' == $elName) {
1411 $cookie[
'expires'] = str_replace(
'"',
'', $elValue);
1412 } elseif (
'path' == $elName ||
'domain' == $elName) {
1413 $cookie[$elName] = urldecode($elValue);
1415 $cookie[$elName] = $elValue;
1419 $this->_cookies[] = $cookie;
1432 if (0 == $this->_chunkLength) {
1433 $line = $this->_sock->readLine();
1434 if (preg_match(
'/^([0-9a-f]+)/i', $line, $matches)) {
1435 $this->_chunkLength = hexdec($matches[1]);
1437 if (0 == $this->_chunkLength) {
1438 $this->_sock->readLine();
1445 $data = $this->_sock->read($this->_chunkLength);
1446 $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data,
'iso-8859-1'): strlen($data);
1447 if (0 == $this->_chunkLength) {
1448 $this->_sock->readLine();
1464 foreach (array_keys($this->_listeners) as $id) {
1465 $this->_listeners[$id]->update($this, $event, $data);
1483 if (HTTP_REQUEST_MBSTRING) {
1484 $oldEncoding = mb_internal_encoding();
1485 mb_internal_encoding(
'iso-8859-1');
1487 $length = strlen($data);
1489 if (18 > $length || strcmp(substr($data, 0, 2),
"\x1f\x8b")) {
1492 $method = ord(substr($data, 2, 1));
1494 return PEAR::raiseError(
'_decodeGzip(): unknown compression method', HTTP_REQUEST_ERROR_GZIP_METHOD);
1496 $flags = ord(substr($data, 3, 1));
1498 return PEAR::raiseError(
'_decodeGzip(): reserved bits are set', HTTP_REQUEST_ERROR_GZIP_DATA);
1505 if ($length - $headerLength - 2 < 8) {
1506 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1508 $extraLength = unpack(
'v', substr($data, 10, 2));
1509 if ($length - $headerLength - 2 - $extraLength[1] < 8) {
1510 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1512 $headerLength += $extraLength[1] + 2;
1516 if ($length - $headerLength - 1 < 8) {
1517 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1519 $filenameLength = strpos(substr($data, $headerLength), chr(0));
1520 if (
false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
1521 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1523 $headerLength += $filenameLength + 1;
1527 if ($length - $headerLength - 1 < 8) {
1528 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1530 $commentLength = strpos(substr($data, $headerLength), chr(0));
1531 if (
false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
1532 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1534 $headerLength += $commentLength + 1;
1538 if ($length - $headerLength - 2 < 8) {
1539 return PEAR::raiseError(
'_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
1541 $crcReal = 0xffff & crc32(substr($data, 0, $headerLength));
1542 $crcStored = unpack(
'v', substr($data, $headerLength, 2));
1543 if ($crcReal != $crcStored[1]) {
1544 return PEAR::raiseError(
'_decodeGzip(): header CRC check failed', HTTP_REQUEST_ERROR_GZIP_CRC);
1549 $tmp = unpack(
'V2', substr($data, -8));
1551 $dataSize = $tmp[2];
1555 $unpacked = gzinflate(substr($data, $headerLength, -8));
1556 if (
false === $unpacked) {
1557 return PEAR::raiseError(
'_decodeGzip(): gzinflate() call failed', HTTP_REQUEST_ERROR_GZIP_READ);
1558 } elseif ($dataSize != strlen($unpacked)) {
1559 return PEAR::raiseError(
'_decodeGzip(): data size check failed', HTTP_REQUEST_ERROR_GZIP_READ);
1560 } elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
1561 return PEAR::raiseError(
'_decodeGzip(): data CRC check failed', HTTP_REQUEST_ERROR_GZIP_CRC);
1563 if (HTTP_REQUEST_MBSTRING) {
1564 mb_internal_encoding($oldEncoding);