*/
class Horde_Http_Request_Curl extends Horde_Http_Request_Base
{
+ /**
+ * Map of HTTP authentication schemes from Horde_Http constants to HTTP_AUTH constants.
+ * @var array
+ */
+ protected $_httpAuthSchemes = array(
+ Horde_Http::AUTH_ANY => CURLAUTH_ANY,
+ Horde_Http::AUTH_BASIC => CURLAUTH_BASIC,
+ Horde_Http::AUTH_DIGEST => CURLAUTH_DIGEST,
+ Horde_Http::AUTH_GSSNEGOTIATE => CURLAUTH_GSSNEGOTIATE,
+ Horde_Http::AUTH_NTLM => CURLAUTH_NTLM,
+ );
+
+ /**
+ * Constructor
+ */
public function __construct($args = array())
{
if (!extension_loaded('curl')) {
}
if ($data) { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); }
- // Proxy
+ // Proxy settings
+ if ($this->proxyServer) {
+ curl_setopt($curl, CURLOPT_PROXY, $this->proxyServer);
+ if ($this->proxyUsername && $this->proxyPassword) {
+ curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUsername . ':' . $this->proxyPassword);
+ curl_setopt($curl, CURLOPT_PROXYAUTH, $this->_httpAuthScheme($this->proxyAuthenticationScheme));
+ }
+ }
- // Set authentication data
+ // Authentication settings
if ($this->username) {
curl_setopt($curl, CURLOPT_USERPWD, $this->username . ':' . $this->password);
- switch ($this->authenticationScheme) {
- case Horde_Http::AUTH_ANY:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
- break;
-
- case Horde_Http::AUTH_BASIC:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- break;
-
- case Horde_Http::AUTH_DIGEST:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
- break;
-
- case Horde_Http::AUTH_GSSNEGOTIATE:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_GSSNEGOTIATE);
- break;
-
- case Horde_Http::AUTH_NTLM:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
- break;
-
- default:
- throw new Horde_Http_Exception('Unsupported authentication scheme (' . $this->authenticationScheme . ')');
- }
+ curl_setopt($curl, CURLOPT_HTTPAUTH, $this->_httpAuthScheme($this->authenticationScheme));
}
// Concatenate the headers
$info = curl_getinfo($curl);
return new Horde_Http_Response_Curl($this->uri, $result, $info);
}
+
+ /**
+ * Translate a Horde_Http::AUTH_* constant to CURLAUTH_*
+ *
+ * @param const
+ * @return const
+ */
+ protected function _httpAuthScheme($httpAuthScheme)
+ {
+ if (!isset($this->_httpAuthSchemes[$httpAuthScheme])) {
+ throw new Horde_Http_Exception('Unsupported authentication scheme (' . $httpAuthScheme . ')');
+ }
+ return $this->_httpAuthSchemes[$httpAuthScheme];
+ }
}
*/
class Horde_Http_Request_Fopen extends Horde_Http_Request_Base
{
- public function __construct()
+ public function __construct($args = array())
{
if (!ini_get('allow_url_fopen')) {
throw new Horde_Http_Exception('allow_url_fopen must be enabled');
}
+
+ parent::__construct($args);
}
/**
$opts = array('http' => array());
- // Proxy settings - check first, so we can include the correct headers
+ // Proxy settings
if ($this->proxyServer) {
$opts['http']['proxy'] = 'tcp://' . $this->proxyServer;
$opts['http']['request_fulluri'] = true;
}
}
- // Set authentication data
+ // Authentication settings
if ($this->username) {
switch ($this->authenticationScheme) {
case Horde_Http::AUTH_BASIC:
*/
class Horde_Http_Request_Peclhttp extends Horde_Http_Request_Base
{
- public static $methods = array(
+ /**
+ * Map of HTTP methods to HTTP_METH_* constants
+ * @var array
+ */
+ protected $_httpMethods = array(
'GET' => HTTP_METH_GET,
'HEAD' => HTTP_METH_HEAD,
'POST' => HTTP_METH_POST,
'DELETE' => HTTP_METH_DELETE,
);
- public function __construct()
+ /**
+ * Map of HTTP authentication schemes from Horde_Http constants to HTTP_AUTH constants.
+ * @var array
+ */
+ protected $_httpAuthSchemes = array(
+ Horde_Http::AUTH_ANY => HTTP_AUTH_ANY,
+ Horde_Http::AUTH_BASIC => HTTP_AUTH_BASIC,
+ Horde_Http::AUTH_DIGEST => HTTP_AUTH_DIGEST,
+ Horde_Http::AUTH_GSSNEGOTIATE => HTTP_AUTH_GSSNEG,
+ Horde_Http::AUTH_NTLM => HTTP_AUTH_NTLM,
+ );
+
+ /**
+ * Constructor
+ *
+ * @throws Horde_Http_Exception
+ */
+ public function __construct($args = array())
{
if (!class_exists('HttpRequest', false)) {
throw new Horde_Http_Exception('The pecl_http extension is not installed. See http://php.net/http.install');
}
+
+ parent::__construct($args);
}
/**
*/
public function send()
{
- $httpRequest = new HttpRequest($this->uri, self::$methods[$this->method]);
+ $httpRequest = new HttpRequest($this->uri, $this->_httpMethods[$this->method]);
$httpRequest->setHeaders($this->headers);
$data = $this->data;
$httpOptions = array();
- // Proxy
+ // Proxy settings
+ if ($this->proxyServer) {
+ $httpOptions['proxyhost'] = $this->proxyServer;
+ if ($this->proxyUsername && $this->proxyPassword) {
+ $httpOptions['proxyauth'] = $this->proxyUsername . ':' . $this->proxyPassword;
+ $httpOptions['proxyauthtype'] = $this->_httpAuthScheme($this->proxyAuthenticationScheme);
+ }
+ }
- // Set authentication data
+ // Authentication settings
if ($this->username) {
$httpOptions['httpauth'] = $this->username . ':' . $this->password;
- switch ($this->authenticationScheme) {
- case Horde_Http::AUTH_ANY:
- $httpOptions['httpauthtype'] = HTTP_AUTH_ANY;
- break;
-
- case Horde_Http::AUTH_BASIC:
- $httpOptions['httpauthtype'] = HTTP_AUTH_BASIC;
- break;
-
- case Horde_Http::AUTH_DIGEST:
- $httpOptions['httpauthtype'] = HTTP_AUTH_DIGEST;
- break;
-
- case Horde_Http::AUTH_GSSNEGOTIATE:
- $httpOptions['httpauthtype'] = HTTP_AUTH_GSSNEG;
- break;
-
- case Horde_Http::AUTH_NTLM:
- $httpOptions['httpauthtype'] = HTTP_AUTH_NTLM;
- break;
-
- default:
- throw new Horde_Http_Exception('Unsupported authentication scheme (' . $this->authenticationScheme . ')');
- }
+ $httpOptions['httpauthtype'] = $this->_httpAuthScheme($this->authenticationScheme);
}
// Set options
return new Horde_Http_Response_Peclhttp($this->uri, $httpResponse);
}
+
+ /**
+ * Translate a Horde_Http::AUTH_* constant to HTTP_AUTH_*
+ *
+ * @param const
+ * @return const
+ */
+ protected function _httpAuthScheme($httpAuthScheme)
+ {
+ if (!isset($this->_httpAuthSchemes[$httpAuthScheme])) {
+ throw new Horde_Http_Exception('Unsupported authentication scheme (' . $httpAuthScheme . ')');
+ }
+ return $this->_httpAuthSchemes[$httpAuthScheme];
+ }
}