/**
* Send a GET request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function get($uri = null, $headers = array())
/**
* Send a POST request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function post($uri = null, $data = null, $headers = array())
/**
* Send a PUT request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function put($uri = null, $data = null, $headers = array())
/**
* Send a DELETE request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function delete($uri = null, $headers = array())
* Send a HEAD request
* @TODO
*
+ * @throws Horde_Http_Exception
* @return ? Probably just the status
*/
public function head($uri = null, $headers = array())
/**
* Send an HTTP request
*
- * @param string $method HTTP request method (GET, PUT, etc.)
- * @param string $uri URI to request, if different from $this->uri
- * @param mixed $data Request data. Can be an array of form data that will be
- * encoded automatically, or a raw string.
- * @param array $headers Any headers specific to this request. They will
- * be combined with $this->_headers, and override
- * headers of the same name for this request only.
+ * @param string $method HTTP request method (GET, PUT, etc.)
+ * @param string $uri URI to request, if different from $this->uri
+ * @param mixed $data Request data. Can be an array of form data that
+ * will be encoded automatically, or a raw string.
+ * @param array $headers Any headers specific to this request. They will
+ * be combined with $this->_headers, and override
+ * headers of the same name for this request only.
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function request($method, $uri = null, $data = null, $headers = array())
class Horde_Http_Request_Curl extends Horde_Http_Request_Base
{
/**
- * Map of HTTP authentication schemes from Horde_Http constants to HTTP_AUTH constants.
+ * Map of HTTP authentication schemes from Horde_Http constants to
+ * HTTP_AUTH constants.
+ *
* @var array
*/
protected $_httpAuthSchemes = array(
/**
* Constructor
+ *
+ * @throws Horde_Http_Exception
*/
public function __construct($args = array())
{
/**
* Send this HTTP request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function send()
// POST data isn't passed.
$data = http_build_query($data);
}
- if ($data) { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); }
+ if ($data) {
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+ }
// Proxy settings
if ($this->proxyServer) {
* Translate a Horde_Http::AUTH_* constant to CURLAUTH_*
*
* @param const
+ * @throws Horde_Http_Exception
* @return const
*/
protected function _httpAuthScheme($httpAuthScheme)
*/
class Horde_Http_Request_Fopen extends Horde_Http_Request_Base
{
+ /**
+ * Constructor
+ *
+ * @throws Horde_Http_Exception
+ */
public function __construct($args = array())
{
if (!ini_get('allow_url_fopen')) {
/**
* Send this HTTP request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function send()
/**
* Send this HTTP request
*
+ * @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function send()
* Translate a Horde_Http::AUTH_* constant to HTTP_AUTH_*
*
* @param const
+ * @throws Horde_Http_Exception
* @return const
*/
protected function _httpAuthScheme($httpAuthScheme)
abstract class Horde_Http_Response_Base
{
/**
- * Fetched URI
+ * Fetched URI.
+ *
* @var string
*/
public $uri;
/**
- * HTTP protocol version that was used
+ * HTTP protocol version that was used.
+ *
* @var float
*/
public $httpVersion;
/**
- * HTTP response code
+ * HTTP response code.
+ *
* @var integer
*/
public $code;
/**
- * Response headers
+ * Response headers.
+ *
* @var array
*/
public $headers;
/**
- * Parse an array of response headers, mindful of line
- * continuations, etc.
+ * Parses an array of response headers, mindful of line continuations, etc.
*
* @param array $headers
+ *
* @return array
*/
protected function _parseHeaders($headers)
$lastHeader = null;
foreach ($headers as $headerLine) {
- // stream_get_meta returns all headers generated while processing a
- // request, including ones for redirects before an eventually successful
- // request. We just want the last one, so whenever we hit a new HTTP
- // header, throw out anything parsed previously and start over.
+ // stream_get_meta returns all headers generated while processing
+ // a request, including ones for redirects before an eventually
+ // successful request. We just want the last one, so whenever we
+ // hit a new HTTP header, throw out anything parsed previously and
+ // start over.
if (preg_match('/^HTTP\/(\d.\d) (\d{3})/', $headerLine, $httpMatches)) {
$this->httpVersion = $httpMatches[1];
$this->code = (int)$httpMatches[2];
}
/**
- * Return the body of the HTTP response.
+ * Returns the body of the HTTP response.
*
+ * @throws Horde_Http_Exception
* @return string HTTP response body.
*/
abstract public function getBody();
/**
- * Return a stream pointing to the response body that can be used
- * with all standard PHP stream functions.
+ * Returns a stream pointing to the response body that can be used with all
+ * standard PHP stream functions.
*/
public function getStream()
{
}
/**
- * Get the value of a single response header.
+ * Returns the value of a single response header.
*
- * @param string $header Header name to get ('Content-Type', 'Content-Length', etc.). This is case sensitive.
+ * @param string $header Header name to get ('Content-Type',
+ * 'Content-Length', etc.). This is case sensitive.
*
* @return string HTTP header value.
*/
class Horde_Http_Response_Curl extends Horde_Http_Response_Base
{
/**
- * Info on the request obtained from curl_getinfo()
+ * Info on the request obtained from curl_getinfo().
+ *
* @var array
*/
protected $_info = array();
/**
- * Response body
+ * Response body.
+ *
* @var string
*/
protected $_body;
/**
- * Constructor
+ * Constructor.
*
* @param string $uri
* @param string $curlresult
}
/**
- * Return the body of the HTTP response.
+ * Returns the body of the HTTP response.
*
* @return string HTTP response body.
*/
}
/**
- * Parse the combined header/body result from cURL.
+ * Parses the combined header/body result from cURL.
*
* @param string $curlresult
*/
protected function _parseResult($curlresult)
{
$endOfHeaders = strpos($curlresult, "\r\n\r\n");
-
$headers = substr($curlresult, 0, $endOfHeaders);
$this->_parseHeaders($headers);
-
$this->_body = substr($curlresult, $endOfHeaders + 4);
}
/**
- * Process the results of curl_getinfo
+ * Processes the results of curl_getinfo.
*
* @param array $curlinfo
*/
protected function _parseInfo($curlinfo)
{
$this->uri = $curlinfo['url'];
-
$this->_info = $curlinfo;
}
}
class Horde_Http_Response_Fopen extends Horde_Http_Response_Base
{
/**
- * Response body
+ * Response body.
+ *
* @var stream
*/
protected $_stream;
/**
- * Constructor
+ * Constructor.
*/
public function __construct($uri, $stream, $headers = array())
{
}
/**
- * Return the body of the HTTP response.
+ * Returns the body of the HTTP response.
*
+ * @throws Horde_Http_Exception
* @return string HTTP response body.
*/
public function getBody()
}
/**
- * Return a stream pointing to the response body that can be used
- * with all standard PHP stream functions.
+ * Returns a stream pointing to the response body that can be used with
+ * all standard PHP stream functions.
*/
public function getStream()
{
class Horde_Http_Response_Peclhttp extends Horde_Http_Response_Base
{
/**
- * HttpMessage object
+ * HttpMessage object.
+ *
* @var HttpMessage
*/
protected $_message;
/**
- * Constructor
+ * Constructor.
*
* @param string $uri
* @param HttpMessage $message
$this->uri = $uri;
$this->httpVersion = $message->getHttpVersion();
$this->code = $message->getResponseCode();
-
$this->_message = $message;
-
foreach ($message->getHeaders() as $k => $v) {
$this->headers[strtolower($k)] = $v;
}