]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/curlclient.php
Reorganize, make bare auth work, output If-Modified-Since header
[quix0rs-gnu-social.git] / lib / curlclient.php
index f45c3c2f4a01c4bd7e88b88a20090e160e7bce18..36fc7d157e71e4a41b54228081932ecf030cadae 100644 (file)
@@ -1,6 +1,6 @@
 n<?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Utility class for wrapping Curl
  *
@@ -20,11 +20,11 @@ n<?php
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  HTTP
- * @package   Laconica
+ * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
  * @copyright 2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
 if (!defined('STATUSNET')) {
@@ -39,10 +39,10 @@ define(CURLCLIENT_VERSION, "0.1");
  * Makes Curl HTTP client calls within our HTTPClient framework
  *
  * @category HTTP
- * @package  Laconica
+ * @package  StatusNet
  * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  */
 
 class CurlClient extends HTTPClient
@@ -88,10 +88,33 @@ class CurlClient extends HTTPClient
         return $this->parseResults($result);
     }
 
+    function post($url, $headers=null, $body=null)
+    {
+        $ch = curl_init($url);
+
+        $this->setup($ch);
+
+        curl_setopt($ch, CURLOPT_POST, true);
+
+        if (!is_null($body)) {
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
+        }
+
+        if (!is_null($headers)) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        }
+
+        $result = curl_exec($ch);
+
+        curl_close($ch);
+
+        return $this->parseResults($result);
+    }
+
     function setup($ch)
     {
         curl_setopt_array($ch,
-                          array(CURLOPT_USERAGENT, $this->userAgent(),
+                          array(CURLOPT_USERAGENT => $this->userAgent(),
                                 CURLOPT_HEADER => true,
                                 CURLOPT_RETURNTRANSFER => true));
     }