--- /dev/null
+<?php
+/**
+ * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package Horde_Http
+ */
+
+/**
+ * Constants
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package Horde_Http
+ */
+class Horde_Http
+{
+ /**
+ * Authentication schemes
+ */
+ const AUTH_ANY = 'ANY';
+ const AUTH_BASIC = 'BASIC';
+ const AUTH_DIGEST = 'DIGEST';
+ const AUTH_NTLM = 'NTLM';
+ const AUTH_GSSNEGOTIATE = 'GSSNEGOTIATE';
+}
protected $_headers = array();
/**
+ * Authentication data
+ * @var array
+ * @see getAuth()
+ */
+ protected $_auth;
+
+ /**
* Request data. Can be an array of form data that will be encoded
* automatically, or a raw string
* @var mixed
protected $_data;
/**
+ * Authentication username
+ * @var string
+ */
+ protected $_username = '';
+
+ /**
+ * Authentication password
+ * @var string
+ */
+ protected $_password = '';
+
+ /**
+ * Authentication scheme
+ * @var const Horde_Http::AUTH_*
+ */
+ protected $_authenticationScheme = Horde_Http::AUTH_BASIC;
+
+ /**
* Proxy server
* @var string
*/
* Proxy username
* @var string
*/
- protected $_proxyUser = null;
+ protected $_proxyUsername = null;
/**
* Proxy password
* @var string
*/
- protected $_proxyPass = null;
+ protected $_proxyPassword = null;
+
+ /**
+ * Proxy authentication schem
+ * @var const Horde_Http::AUTH_*
+ */
+ protected $_proxyAuthenticationScheme = Horde_Http::AUTH_BASIC;
/**
* HTTP timeout
}
if ($data) { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); }
+ // Proxy
+
+ // Set authentication data
+ 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 . ')');
+ }
+ }
+
// Concatenate the headers
$hdr = array();
foreach ($this->headers as $header => $value) {
if ($this->proxyServer) {
$opts['http']['proxy'] = 'tcp://' . $this->proxyServer;
$opts['http']['request_fulluri'] = true;
- if ($this->proxyUser && $this->proxyPass) {
- $headers['Proxy-Authorization'] = 'Basic ' . base64_encode($this->proxyUser . ':' . $this->proxyPass);
+ if ($this->proxyUsername && $this->proxyPassword) {
+ // @TODO check $this->proxyAuthenticationScheme
+ $headers['Proxy-Authorization'] = 'Basic ' . base64_encode($this->proxyUsername . ':' . $this->proxyPassword);
+ }
+ }
+
+ // Set authentication data
+ if ($this->username) {
+ switch ($this->authenticationScheme) {
+ case Horde_Http::AUTH_BASIC:
+ $headers['Authorization'] = 'Basic ' . base64_encode($this->username . ':' . $this->password);
+ break;
+
+ default:
+ throw new Horde_Http_Exception('Unsupported authentication scheme (' . $this->authenticationScheme . ')');
}
}
$httpRequest->setRawPostData($data);
}
+ $httpOptions = array();
+
+ // Proxy
+
+ // Set authentication data
+ 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 . ')');
+ }
+ }
+
+ // Set options
+ $httpRequest->setOptions($httpOptions);
+
try {
$httpResponse = $httpRequest->send();
} catch (HttpException $e) {
<dir name="Response">
</dir> <!-- /lib/Horde/Http/Response -->
</dir> <!-- /lib/Horde/Http -->
+ <file name="Http.php" role="php" />
</dir> <!-- /lib/Horde -->
</dir> <!-- /lib/ -->
</dir> <!-- / -->
<install name="lib/Horde/Http/Response/Fopen.php" as="Horde/Http/Response/Fopen.php" />
<install name="lib/Horde/Http/Response/Mock.php" as="Horde/Http/Response/Mock.php" />
<install name="lib/Horde/Http/Response/Peclhttp.php" as="Horde/Http/Response/Peclhttp.php" />
+ <install name="lib/Horde/Http.php" as="Horde/Http.php" />
</filelist>
</phprelease>
</package>