From: <ny...@us...> - 2008-07-18 17:00:32
|
Revision: 13728 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=13728&view=rev Author: nyloth Date: 2008-07-18 17:00:40 +0000 (Fri, 18 Jul 2008) Log Message: ----------- [NEW] pear HTTP_Request: update to last stable version 1.4.2. Modified Paths: -------------- trunk/lib/pear/HTTP/Request/Listener.php trunk/lib/pear/HTTP/Request.php Removed Paths: ------------- trunk/lib/pear/HTTP/docs/ Modified: trunk/lib/pear/HTTP/Request/Listener.php =================================================================== --- trunk/lib/pear/HTTP/Request/Listener.php 2008-07-18 16:53:40 UTC (rev 13727) +++ trunk/lib/pear/HTTP/Request/Listener.php 2008-07-18 17:00:40 UTC (rev 13728) @@ -39,7 +39,7 @@ * @author Alexey Borzov <av...@ph...> * @copyright 2002-2007 Richard Heyes * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: Id: Listener.php,v 1.3 2007/05/18 10:33:31 avb Exp + * @version CVS: $Id: Listener.php,v 1.3 2007/05/18 10:33:31 avb Exp $ * @link http://pear.php.net/package/HTTP_Request/ */ @@ -52,7 +52,7 @@ * @category HTTP * @package HTTP_Request * @author Alexey Borzov <av...@ph...> - * @version Release: 1.4.1 + * @version Release: 1.4.2 */ class HTTP_Request_Listener { Modified: trunk/lib/pear/HTTP/Request.php =================================================================== --- trunk/lib/pear/HTTP/Request.php 2008-07-18 16:53:40 UTC (rev 13727) +++ trunk/lib/pear/HTTP/Request.php 2008-07-18 17:00:40 UTC (rev 13728) @@ -40,7 +40,7 @@ * @author Alexey Borzov <av...@ph...> * @copyright 2002-2007 Richard Heyes * @license http://opensource.org/licenses/bsd-license.php New BSD License - * @version CVS: Id: Request.php,v 1.55 2007/05/18 19:20:12 avb Exp + * @version CVS: $Id: Request.php,v 1.58 2007/10/26 13:45:56 avb Exp $ * @link http://pear.php.net/package/HTTP_Request/ */ @@ -51,7 +51,7 @@ /** * Socket class */ -require_once 'Net/Socket.php'; +require_once 'lib/pear/Net/Socket.php'; /** * URL handling class */ @@ -70,6 +70,20 @@ /**#@-*/ /**#@+ + * Constants for HTTP request error codes + */ +define('HTTP_REQUEST_ERROR_FILE', 1); +define('HTTP_REQUEST_ERROR_URL', 2); +define('HTTP_REQUEST_ERROR_PROXY', 4); +define('HTTP_REQUEST_ERROR_REDIRECTS', 8); +define('HTTP_REQUEST_ERROR_RESPONSE', 16); +define('HTTP_REQUEST_ERROR_GZIP_METHOD', 32); +define('HTTP_REQUEST_ERROR_GZIP_READ', 64); +define('HTTP_REQUEST_ERROR_GZIP_DATA', 128); +define('HTTP_REQUEST_ERROR_GZIP_CRC', 256); +/**#@-*/ + +/**#@+ * Constants for HTTP protocol versions */ define('HTTP_REQUEST_HTTP_VER_1_0', '1.0', true); @@ -102,7 +116,7 @@ * @package HTTP_Request * @author Richard Heyes <ri...@ph...> * @author Alexey Borzov <av...@ph...> - * @version Release: 1.4.1 + * @version Release: 1.4.2 */ class HTTP_Request { @@ -572,11 +586,11 @@ function addFile($inputName, $fileName, $contentType = 'application/octet-stream') { if (!is_array($fileName) && !is_readable($fileName)) { - return PEAR::raiseError("File '{$fileName}' is not readable"); + return PEAR::raiseError("File '{$fileName}' is not readable", HTTP_REQUEST_ERROR_FILE); } elseif (is_array($fileName)) { foreach ($fileName as $name) { if (!is_readable($name)) { - return PEAR::raiseError("File '{$name}' is not readable"); + return PEAR::raiseError("File '{$name}' is not readable", HTTP_REQUEST_ERROR_FILE); } } } @@ -662,7 +676,7 @@ function sendRequest($saveBody = true) { if (!is_a($this->_url, 'Net_URL')) { - return PEAR::raiseError('No URL given.'); + return PEAR::raiseError('No URL given', HTTP_REQUEST_ERROR_URL); } $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host; @@ -672,7 +686,7 @@ // we running on at least 4.3.0 if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) { if (isset($this->_proxy_host)) { - return PEAR::raiseError('HTTPS proxies are not supported.'); + return PEAR::raiseError('HTTPS proxies are not supported', HTTP_REQUEST_ERROR_PROXY); } $host = 'ssl://' . $host; } @@ -792,7 +806,7 @@ // Too many redirects } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) { - return PEAR::raiseError('Too many redirects'); + return PEAR::raiseError('Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS); } return true; @@ -880,10 +894,14 @@ $path = $this->_url->path . $querystring; $url = $host . $port . $path; + if (!strlen($url)) { + $url = '/'; + } + $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n"; if (in_array($this->_method, $this->_bodyDisallowed) || - (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || + (0 == strlen($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method || (empty($this->_postData) && empty($this->_postFiles))))) { $this->removeHeader('Content-Type'); @@ -907,7 +925,7 @@ // No post data or wrong method, so simply add a final CRLF if (in_array($this->_method, $this->_bodyDisallowed) || - (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) { + (HTTP_REQUEST_METHOD_POST != $this->_method && 0 == strlen($this->_body))) { $request .= "\r\n"; @@ -961,12 +979,17 @@ $request .= $postdata; // Explicitly set request body - } elseif (!empty($this->_body)) { + } elseif (0 < strlen($this->_body)) { $request .= 'Content-Length: ' . (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) . "\r\n\r\n"; $request .= $this->_body; + + // Terminate headers with CRLF on POST request with no body, too + } else { + + $request .= "\r\n"; } return $request; @@ -1073,7 +1096,7 @@ * @package HTTP_Request * @author Richard Heyes <ri...@ph...> * @author Alexey Borzov <av...@ph...> - * @version Release: 1.4.1 + * @version Release: 1.4.2 */ class HTTP_Response { @@ -1164,7 +1187,7 @@ do { $line = $this->_sock->readLine(); if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) { - return PEAR::raiseError('Malformed response.'); + return PEAR::raiseError('Malformed response', HTTP_REQUEST_ERROR_RESPONSE); } else { $this->_protocol = 'HTTP/' . $http_version; $this->_code = intval($returncode); @@ -1384,11 +1407,11 @@ } $method = ord(substr($data, 2, 1)); if (8 != $method) { - return PEAR::raiseError('_decodeGzip(): unknown compression method'); + return PEAR::raiseError('_decodeGzip(): unknown compression method', HTTP_REQUEST_ERROR_GZIP_METHOD); } $flags = ord(substr($data, 3, 1)); if ($flags & 224) { - return PEAR::raiseError('_decodeGzip(): reserved bits are set'); + return PEAR::raiseError('_decodeGzip(): reserved bits are set', HTTP_REQUEST_ERROR_GZIP_DATA); } // header is 10 bytes minimum. may be longer, though. @@ -1396,45 +1419,45 @@ // extra fields, need to skip 'em if ($flags & 4) { if ($length - $headerLength - 2 < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $extraLength = unpack('v', substr($data, 10, 2)); if ($length - $headerLength - 2 - $extraLength[1] < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $headerLength += $extraLength[1] + 2; } // file name, need to skip that if ($flags & 8) { if ($length - $headerLength - 1 < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $filenameLength = strpos(substr($data, $headerLength), chr(0)); if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $headerLength += $filenameLength + 1; } // comment, need to skip that also if ($flags & 16) { if ($length - $headerLength - 1 < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $commentLength = strpos(substr($data, $headerLength), chr(0)); if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $headerLength += $commentLength + 1; } // have a CRC for header. let's check if ($flags & 1) { if ($length - $headerLength - 2 < 8) { - return PEAR::raiseError('_decodeGzip(): data too short'); + return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA); } $crcReal = 0xffff & crc32(substr($data, 0, $headerLength)); $crcStored = unpack('v', substr($data, $headerLength, 2)); if ($crcReal != $crcStored[1]) { - return PEAR::raiseError('_decodeGzip(): header CRC check failed'); + return PEAR::raiseError('_decodeGzip(): header CRC check failed', HTTP_REQUEST_ERROR_GZIP_CRC); } $headerLength += 2; } @@ -1446,11 +1469,11 @@ // finally, call the gzinflate() function $unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize); if (false === $unpacked) { - return PEAR::raiseError('_decodeGzip(): gzinflate() call failed'); + return PEAR::raiseError('_decodeGzip(): gzinflate() call failed', HTTP_REQUEST_ERROR_GZIP_READ); } elseif ($dataSize != strlen($unpacked)) { - return PEAR::raiseError('_decodeGzip(): data size check failed'); + return PEAR::raiseError('_decodeGzip(): data size check failed', HTTP_REQUEST_ERROR_GZIP_READ); } elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) { - return PEAR::raiseError('_decodeGzip(): data CRC check failed'); + return PEAR::raiseError('_decodeGzip(): data CRC check failed', HTTP_REQUEST_ERROR_GZIP_CRC); } if (HTTP_REQUEST_MBSTRING) { mb_internal_encoding($oldEncoding); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |