cvs: pear /HTTP_Request Request.php
| From: | Richard Heyes | Date: | Mon, 08 Apr 2002 20:19:36 +0000 |
| Subject: | cvs: pear /HTTP_Request Request.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3151@lists.php.net to get a copy of this message | ||
richard Mon Apr 8 16:19:36 2002 EDT
Modified files:
/pear/HTTP_Request Request.php
Log:
* Fixed error handling
Index: pear/HTTP_Request/Request.php
diff -u pear/HTTP_Request/Request.php:1.12 pear/HTTP_Request/Request.php:1.13
--- pear/HTTP_Request/Request.php:1.12 Fri Mar 22 08:06:38 2002
+++ pear/HTTP_Request/Request.php Mon Apr 8 16:19:36 2002
@@ -15,10 +15,16 @@
// | Author: Richard Heyes <richard@phpguru.org> |
// +----------------------------------------------------------------------+
//
-// $Id: Request.php,v 1.12 2002/03/22 13:06:38 richard Exp $
+// $Id: Request.php,v 1.13 2002/04/08 20:19:36 richard Exp $
//
// HTTP_Request Class
//
+// Simple example, (Fetches yahoo.com and displays it):
+//
+// $a = &new HTTP_Request('http://www.yahoo.com/');
+// $a->sendRequest();
+// echo $a->getResponseBody();
+//
require_once('Net/Socket.php');
require_once('Net/URL.php');
@@ -306,16 +312,24 @@
* Sends the request
*
* @access public
+ * @return mixed PEAR error on error, true otherwise
*/
function sendRequest()
{
$host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host;
$port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port;
- $this->_sock->connect($host, $port, null, $this->_timeout);
- $this->_sock->write($this->_buildRequest());
+ if ( PEAR::isError($err = $this->_sock->connect($host, $port, null,
$this->_timeout))
+ OR PEAR::isError($err = $this->_sock->write($this->_buildRequest())) ) {
+
+ return $err;
+ }
- $this->readResponse();
+ if (PEAR::isError($err = $this->readResponse()) ) {
+ return $err;
+ }
+
+ return true;
}
/**
@@ -406,7 +420,7 @@
*/
function readResponse()
{
- $this->_response =& new HTTP_Response($this->_sock);
+ $this->_response = &new HTTP_Response($this->_sock);
}
}
@@ -451,11 +465,17 @@
*
* Reads the entire response, parse out the headers, and checks
* for chunked encoding.
+ *
+ * @return mixed PEAR Error on error, true otherwise
*/
function HTTP_Response(&$sock)
{
// Fetch all
$response = $sock->readAll();
+
+ if (PEAR::isError($response)) {
+ return $response;
+ }
// Sort out headers
$headers = substr($response, 0, strpos($response, "\r\n\r\n"));
@@ -498,6 +518,9 @@
// Save chunks to $this->_body
$this->_body = implode('', $chunks);
}
+
+ return true;
}
}
+
?>