2009-03-26 19:26:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-09-16 03:31:52 +01:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2009-03-26 19:26:19 +00:00
|
|
|
*
|
|
|
|
* 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
|
2009-09-16 03:31:52 +01:00
|
|
|
* @package StatusNet
|
2009-09-16 03:28:59 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-09-16 03:31:52 +01:00
|
|
|
* @copyright 2009 StatusNet, Inc.
|
2009-03-26 19:26:19 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-09-16 03:31:52 +01:00
|
|
|
* @link http://status.net/
|
2009-03-26 19:26:19 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-16 02:22:47 +01:00
|
|
|
if (!defined('STATUSNET')) {
|
2009-03-26 19:26:19 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-09-16 01:40:03 +01:00
|
|
|
* Useful structure for HTTP responses
|
2009-03-26 19:26:19 +00:00
|
|
|
*
|
|
|
|
* 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
|
2009-09-16 03:31:52 +01:00
|
|
|
* @package StatusNet
|
2009-09-16 03:28:59 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-03-26 19:26:19 +00:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-09-16 03:31:52 +01:00
|
|
|
* @link http://status.net/
|
2009-03-26 19:26:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
class HTTPResponse
|
|
|
|
{
|
2009-09-16 02:50:19 +01:00
|
|
|
public $code = null;
|
2009-10-22 21:20:56 +01:00
|
|
|
public $headers = array();
|
2009-09-16 02:50:19 +01:00
|
|
|
public $body = null;
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 01:40:03 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2009-09-16 03:31:52 +01:00
|
|
|
* @package StatusNet
|
2009-09-16 03:28:59 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-09-16 01:40:03 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-09-16 03:31:52 +01:00
|
|
|
* @link http://status.net/
|
2009-09-16 01:40:03 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
class HTTPClient
|
2009-03-26 19:26:19 +00:00
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
static $_client = null;
|
|
|
|
|
|
|
|
static function start()
|
2009-03-26 19:26:19 +00:00
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
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;
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function head($url, $headers)
|
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
throw new Exception("HEAD method unimplemented");
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function get($url, $headers)
|
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
throw new Exception("GET method unimplemented");
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function post($url, $headers, $body)
|
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
throw new Exception("POST method unimplemented");
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function put($url, $headers, $body)
|
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
throw new Exception("PUT method unimplemented");
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function delete($url, $headers)
|
|
|
|
{
|
2009-09-16 01:40:03 +01:00
|
|
|
throw new Exception("DELETE method unimplemented");
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|
2009-09-16 02:22:47 +01:00
|
|
|
|
|
|
|
function userAgent()
|
|
|
|
{
|
|
|
|
return "StatusNet/".STATUSNET_VERSION." (".STATUSNET_CODENAME.")";
|
|
|
|
}
|
2009-03-26 19:26:19 +00:00
|
|
|
}
|