<?xml version="1.0"?>
<?xml-stylesheet 
 href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"
?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel rdf:about="http://pear.php.net/bugs/12335/bug">
    <title>PEAR Bug #12335</title>
    <link>http://pear.php.net/bugs/12335</link>
    <description>[Closed] Add error codes to HTTP_Request</description>
    <dc:language>en-us</dc:language>
    <dc:creator>pear-webmaster@lists.php.net</dc:creator>
    <dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
    <admin:generatorAgent rdf:resource="http://pear.php.net/bugs"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <items>
     <rdf:Seq>
      <rdf:li rdf:resource="http://pear.php.net/bugs/12335"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/12335/2007-10-24+15%3A26%3A08#2007-10-24+15%3A26%3A08"/>
      <rdf:li rdf:resource="http://pear.php.net/bugs/12335/2007-10-24+14%3A33%3A57#2007-10-24+14%3A33%3A57"/>
     </rdf:Seq>
    </items>
  </channel>
    <item rdf:about="http://pear.php.net/bugs/12335">
      <title>jstump</title>
      <link>http://pear.php.net/bugs/12335</link>
      <description><![CDATA[<pre>HTTP_Request Feature/Change Request
Reported by jstump
2007-10-24T18:31:40-00:00
PHP: Irrelevant OS: All Package Version: 1.4.1

Description:
------------
I added error codes to all of the PEAR::raiseError()'s in HTTP_Request. String comparison for error types makes me a sad panda.</pre>]]></description>
      <content:encoded><![CDATA[<pre>HTTP_Request Feature/Change Request
Reported by jstump
2007-10-24T18:31:40-00:00
PHP: Irrelevant OS: All Package Version: 1.4.1

Description:
------------
I added error codes to all of the PEAR::raiseError()'s in HTTP_Request. String comparison for error types makes me a sad panda.</pre>]]></content:encoded>
      <dc:date>2007-10-24T18:31:40-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/12335/2007-10-24+15%3A26%3A08#2007-10-24+15%3A26%3A08">
      <title>avb [2007-10-24 19:26]</title>
      <link>http://pear.php.net/bugs/12335#1193253968</link>
      <description><![CDATA[<pre>This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.</pre>]]></description>
      <content:encoded><![CDATA[<pre>This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.</pre>]]></content:encoded>
      <dc:date>2007-10-24T19:26:08-00:00</dc:date>
    </item>
    <item rdf:about="http://pear.php.net/bugs/12335/2007-10-24+14%3A33%3A57#2007-10-24+14%3A33%3A57">
      <title>jstump [2007-10-24 18:33]</title>
      <link>http://pear.php.net/bugs/12335#1193250837</link>
      <description><![CDATA[<pre>Index: Request.php
===================================================================
RCS file: /repository/pear/HTTP_Request/Request.php,v
retrieving revision 1.56
diff -u -r1.56 Request.php
--- Request.php	14 Aug 2007 18:42:19 -0000	1.56
+++ Request.php	24 Oct 2007 18:23:08 -0000
@@ -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);
@@ -572,11 +586,11 @@
     function addFile($inputName, $fileName, $contentType = 'application/octet-stream')
     {
         if (!is_array($fileName) &amp;&amp; !is_readable($fileName)) {
-            return PEAR::raiseError(&quot;File '{$fileName}' is not readable&quot;);
+            return PEAR::raiseError(&quot;File '{$fileName}' is not readable&quot;, HTTP_REQUEST_ERROR_FILE);
         } elseif (is_array($fileName)) {
             foreach ($fileName as $name) {
                 if (!is_readable($name)) {
-                    return PEAR::raiseError(&quot;File '{$name}' is not readable&quot;);
+                    return PEAR::raiseError(&quot;File '{$name}' is not readable&quot;, HTTP_REQUEST_ERROR_FILE);
                 }
             }
         }
@@ -662,7 +676,7 @@
     function sendRequest($saveBody = true)
     {
         if (!is_a($this-&gt;_url, 'Net_URL')) {
-            return PEAR::raiseError('No URL given.');
+            return PEAR::raiseError('No URL given', HTTP_REQUEST_ERROR_URL);
         }
 
         $host = isset($this-&gt;_proxy_host) ? $this-&gt;_proxy_host : $this-&gt;_url-&gt;host;
@@ -672,7 +686,7 @@
         // we running on at least 4.3.0
         if (strcasecmp($this-&gt;_url-&gt;protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) {
             if (isset($this-&gt;_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-&gt;_allowRedirects AND $this-&gt;_redirects &gt; $this-&gt;_maxRedirects) {
-            return PEAR::raiseError('Too many redirects');
+            return PEAR::raiseError('Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS);
         }
 
         return true;
@@ -880,6 +894,10 @@
         $path = $this-&gt;_url-&gt;path . $querystring;
         $url  = $host . $port . $path;
 
+        if (!strlen($url)) {
+            $url = '/';
+        }
+
         $request = $this-&gt;_method . ' ' . $url . ' HTTP/' . $this-&gt;_http . &quot;\r\n&quot;;
 
         if (in_array($this-&gt;_method, $this-&gt;_bodyDisallowed) ||
@@ -1169,7 +1187,7 @@
         do {
             $line = $this-&gt;_sock-&gt;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-&gt;_protocol = 'HTTP/' . $http_version;
                 $this-&gt;_code     = intval($returncode);
@@ -1389,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 &amp; 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.
@@ -1401,45 +1419,45 @@
         // extra fields, need to skip 'em
         if ($flags &amp; 4) {
             if ($length - $headerLength - 2 &lt; 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] &lt; 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 &amp; 8) {
             if ($length - $headerLength - 1 &lt; 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 &lt; 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 &amp; 16) {
             if ($length - $headerLength - 1 &lt; 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 &lt; 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 &amp; 1) {
             if ($length - $headerLength - 2 &lt; 8) {
-                return PEAR::raiseError('_decodeGzip(): data too short');
+                return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
             }
             $crcReal   = 0xffff &amp; 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;
         }
@@ -1451,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 &amp; $dataCrc) != (0xffffffff &amp; 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);</pre>]]></description>
      <content:encoded><![CDATA[<pre>Index: Request.php
===================================================================
RCS file: /repository/pear/HTTP_Request/Request.php,v
retrieving revision 1.56
diff -u -r1.56 Request.php
--- Request.php	14 Aug 2007 18:42:19 -0000	1.56
+++ Request.php	24 Oct 2007 18:23:08 -0000
@@ -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);
@@ -572,11 +586,11 @@
     function addFile($inputName, $fileName, $contentType = 'application/octet-stream')
     {
         if (!is_array($fileName) &amp;&amp; !is_readable($fileName)) {
-            return PEAR::raiseError(&quot;File '{$fileName}' is not readable&quot;);
+            return PEAR::raiseError(&quot;File '{$fileName}' is not readable&quot;, HTTP_REQUEST_ERROR_FILE);
         } elseif (is_array($fileName)) {
             foreach ($fileName as $name) {
                 if (!is_readable($name)) {
-                    return PEAR::raiseError(&quot;File '{$name}' is not readable&quot;);
+                    return PEAR::raiseError(&quot;File '{$name}' is not readable&quot;, HTTP_REQUEST_ERROR_FILE);
                 }
             }
         }
@@ -662,7 +676,7 @@
     function sendRequest($saveBody = true)
     {
         if (!is_a($this-&gt;_url, 'Net_URL')) {
-            return PEAR::raiseError('No URL given.');
+            return PEAR::raiseError('No URL given', HTTP_REQUEST_ERROR_URL);
         }
 
         $host = isset($this-&gt;_proxy_host) ? $this-&gt;_proxy_host : $this-&gt;_url-&gt;host;
@@ -672,7 +686,7 @@
         // we running on at least 4.3.0
         if (strcasecmp($this-&gt;_url-&gt;protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) {
             if (isset($this-&gt;_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-&gt;_allowRedirects AND $this-&gt;_redirects &gt; $this-&gt;_maxRedirects) {
-            return PEAR::raiseError('Too many redirects');
+            return PEAR::raiseError('Too many redirects', HTTP_REQUEST_ERROR_REDIRECTS);
         }
 
         return true;
@@ -880,6 +894,10 @@
         $path = $this-&gt;_url-&gt;path . $querystring;
         $url  = $host . $port . $path;
 
+        if (!strlen($url)) {
+            $url = '/';
+        }
+
         $request = $this-&gt;_method . ' ' . $url . ' HTTP/' . $this-&gt;_http . &quot;\r\n&quot;;
 
         if (in_array($this-&gt;_method, $this-&gt;_bodyDisallowed) ||
@@ -1169,7 +1187,7 @@
         do {
             $line = $this-&gt;_sock-&gt;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-&gt;_protocol = 'HTTP/' . $http_version;
                 $this-&gt;_code     = intval($returncode);
@@ -1389,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 &amp; 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.
@@ -1401,45 +1419,45 @@
         // extra fields, need to skip 'em
         if ($flags &amp; 4) {
             if ($length - $headerLength - 2 &lt; 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] &lt; 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 &amp; 8) {
             if ($length - $headerLength - 1 &lt; 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 &lt; 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 &amp; 16) {
             if ($length - $headerLength - 1 &lt; 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 &lt; 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 &amp; 1) {
             if ($length - $headerLength - 2 &lt; 8) {
-                return PEAR::raiseError('_decodeGzip(): data too short');
+                return PEAR::raiseError('_decodeGzip(): data too short', HTTP_REQUEST_ERROR_GZIP_DATA);
             }
             $crcReal   = 0xffff &amp; 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;
         }
@@ -1451,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 &amp; $dataCrc) != (0xffffffff &amp; 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);</pre>]]></content:encoded>
      <dc:date>2007-10-24T18:33:57-00:00</dc:date>
    </item>
</rdf:RDF>