start adding response objects
authorChuck Hagenbuch <chuck@horde.org>
Tue, 15 Sep 2009 02:47:00 +0000 (22:47 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Tue, 15 Sep 2009 02:47:00 +0000 (22:47 -0400)
framework/Http/lib/Horde/Http/Response/Base.php
framework/Http/lib/Horde/Http/Response/Curl.php
framework/Http/package.xml

index 1826d4f..317f0af 100644 (file)
@@ -14,7 +14,7 @@
  * @category Horde
  * @package  Horde_Http
  */
-class Horde_Http_Response_Base
+abstract class Horde_Http_Response_Base
 {
     /**
      * Fetched URI
@@ -53,7 +53,7 @@ class Horde_Http_Response_Base
     {
         $this->uri = $uri;
         $this->_stream = $stream;
-        $this->_parseHeaders($headers);
+        $this->headers = $this->_parseHeaders($headers);
     }
 
     /**
@@ -69,6 +69,8 @@ class Horde_Http_Response_Base
             $headers = explode("\n", $headers);
         }
 
+        $parsedHeaders = array();
+
         $lastHeader = null;
         foreach ($headers as $headerLine) {
             // stream_get_meta returns all headers generated while processing a
@@ -78,7 +80,7 @@ class Horde_Http_Response_Base
             if (preg_match('/^HTTP\/(\d.\d) (\d{3})/', $headerLine, $httpMatches)) {
                 $this->httpVersion = $httpMatches[1];
                 $this->code = (int)$httpMatches[2];
-                $this->headers = array();
+                $parsedHeaders = array();
                 $lastHeader = null;
             }
 
@@ -91,25 +93,27 @@ class Horde_Http_Response_Base
                 $headerName = strtolower($m[1]);
                 $headerValue = $m[2];
 
-                if (isset($this->headers[$headerName])) {
-                    if (!is_array($this->headers[$headerName])) {
-                        $this->headers[$headerName] = array($this->headers[$headerName]);
+                if (isset($parsedHeaders[$headerName])) {
+                    if (!is_array($parsedHeaders[$headerName])) {
+                        $parsedHeaders[$headerName] = array($parsedHeaders[$headerName]);
                     }
 
-                    $this->headers[$headerName][] = $headerValue;
+                    $parsedHeaders[$headerName][] = $headerValue;
                 } else {
-                    $this->headers[$headerName] = $headerValue;
+                    $parsedHeaders[$headerName] = $headerValue;
                 }
                 $lastHeader = $headerName;
             } elseif (preg_match("|^\s+(.+)$|", $headerLine, $m) && !is_null($lastHeader)) {
-                if (is_array($this->headers[$lastHeader])) {
-                    end($this->headers[$lastHeader]);
-                    $this->headers[$lastHeader][key($this->headers[$lastHeader])] .= $m[1];
+                if (is_array($parsedHeaders[$lastHeader])) {
+                    end($parsedHeaders[$lastHeader]);
+                    $parsedHeaders[$lastHeader][key($parsedHeaders[$lastHeader])] .= $m[1];
                 } else {
-                    $this->headers[$lastHeader] .= $m[1];
+                    $parsedHeaders[$lastHeader] .= $m[1];
                 }
             }
         }
+
+        return $parsedHeaders;
     }
 
     /**
index e69de29..7b2eb5f 100644 (file)
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Http
+ */
+
+/**
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Http
+ */
+class Horde_Http_Response_Curl extends Horde_Http_Response_Base
+{
+    /**
+     * Info on the request
+     * @var array
+     */
+    protected $_curlinfo = array();
+
+    /**
+     */
+    public function __construct($curlresult, $curlinfo)
+    {
+        echo $curlresult;
+        $this->parseResponse($curlresult, $curlinfo);
+    }
+
+    /**
+     *
+     */
+    public function parseResponse($curlresult, $curlinfo)
+    {
+        $this->_curlinfo = $curlinfo;
+    }
+
+    /**
+     * Return the body of the HTTP response.
+     *
+     * @return string HTTP response body.
+     */
+    public function getBody()
+    {
+        return $this->_body;
+    }
+}
index 42fe622..460eee2 100644 (file)
@@ -40,6 +40,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
        <file name="Peclhttp.php" role="php" />
       </dir> <!-- /lib/Horde/Http/Request -->
       <dir name="Response">
+       <file name="Base.php" role="php" />
+       <file name="Curl.php" role="php" />
+       <file name="Fopen.php" role="php" />
+       <file name="Mock.php" role="php" />
+       <file name="Peclhttp.php" role="php" />
+      </dir> <!-- /lib/Horde/Http/Response -->
+      <dir name="Response">
       </dir> <!-- /lib/Horde/Http/Response -->
      </dir> <!-- /lib/Horde/Http -->
     </dir> <!-- /lib/Horde -->
@@ -65,6 +72,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Http/Request/Fopen.php" as="Horde/Http/Request/Fopen.php" />
    <install name="lib/Horde/Http/Request/Mock.php" as="Horde/Http/Request/Mock.php" />
    <install name="lib/Horde/Http/Request/Peclhttp.php" as="Horde/Http/Request/Peclhttp.php" />
+   <install name="lib/Horde/Http/Response/Base.php" as="Horde/Http/Response/Base.php" />
+   <install name="lib/Horde/Http/Response/Curl.php" as="Horde/Http/Response/Curl.php" />
+   <install name="lib/Horde/Http/Response/Fopen.php" as="Horde/Http/Response/Fopen.php" />
+   <install name="lib/Horde/Http/Response/Mock.php" as="Horde/Http/Response/Mock.php" />
+   <install name="lib/Horde/Http/Response/Peclhttp.php" as="Horde/Http/Response/Peclhttp.php" />
   </filelist>
  </phprelease>
 </package>