summaryrefslogtreecommitdiff
path: root/lib/httpclient.php
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-09-16 12:40:22 -0700
committerZach Copley <zach@status.net>2009-09-16 12:40:22 -0700
commit0190785b73b52e2c6069c31542f578f812a5e0ab (patch)
treeb0c1184753a0fa10ca8efae0b283ad8ea79fb750 /lib/httpclient.php
parent876f56254d3ccdcc7ba3e9c7693345cef8a6e22b (diff)
parent83b09164573ede90d87a7038a56f651a5f82b9f1 (diff)
Merge branch '0.9.x' into pluginize-twitter-bridge
* 0.9.x: (57 commits) Updated csarven emails to csarven@status.net and removed dupes statusize new HTTP classes dedupe evans change all evans to evan@status.net add post to curlclient fix user-agent for curlclient add get to curl client add cURL client with HEAD method add user agent and correct version check to httpclient statusize OpenID plugin add http client config value update httpclient class move httputil to httpclient Start a common library for HTTP client stuff check correct define (not backwards compatible) Fixed broken list items in installer output Got rid of a bunch of ugly warnings Add Jiminy to notice sources Make it impossible to delete self-subscriptions via the API Fix bad merge d7ae0ed4fd755ebad0788a17d0f2fb6a6ca9d63b ...
Diffstat (limited to 'lib/httpclient.php')
-rw-r--r--lib/httpclient.php122
1 files changed, 122 insertions, 0 deletions
diff --git a/lib/httpclient.php b/lib/httpclient.php
new file mode 100644
index 000000000..c8c8ae5b2
--- /dev/null
+++ b/lib/httpclient.php
@@ -0,0 +1,122 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Utility for doing HTTP-related things
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Action
+ * @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://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+/**
+ * Useful structure for HTTP responses
+ *
+ * We make HTTP calls in several places, and we have several different
+ * ways of doing them. This class hides the specifics of what underlying
+ * library (curl or PHP-HTTP or whatever) that's used.
+ *
+ * @category HTTP
+ * @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://status.net/
+ */
+
+class HTTPResponse
+{
+ public $code = null;
+ public $headers = null;
+ public $body = null;
+}
+
+/**
+ * Utility class for doing HTTP client stuff
+ *
+ * We make HTTP calls in several places, and we have several different
+ * ways of doing them. This class hides the specifics of what underlying
+ * library (curl or PHP-HTTP or whatever) that's used.
+ *
+ * @category HTTP
+ * @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://status.net/
+ */
+
+class HTTPClient
+{
+ static $_client = null;
+
+ static function start()
+ {
+ if (!is_null(self::$_client)) {
+ return self::$_client;
+ }
+
+ $type = common_config('http', 'client');
+
+ switch ($type) {
+ case 'curl':
+ self::$_client = new CurlClient();
+ break;
+ default:
+ throw new Exception("Unknown HTTP client type '$type'");
+ break;
+ }
+
+ return self::$_client;
+ }
+
+ function head($url, $headers)
+ {
+ throw new Exception("HEAD method unimplemented");
+ }
+
+ function get($url, $headers)
+ {
+ throw new Exception("GET method unimplemented");
+ }
+
+ function post($url, $headers, $body)
+ {
+ throw new Exception("POST method unimplemented");
+ }
+
+ function put($url, $headers, $body)
+ {
+ throw new Exception("PUT method unimplemented");
+ }
+
+ function delete($url, $headers)
+ {
+ throw new Exception("DELETE method unimplemented");
+ }
+
+ function userAgent()
+ {
+ return "StatusNet/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")";
+ }
+}