package.xml 0000664 0001750 0001750 00000034253 12207100265 011301 0 ustar jan jan
Horde_Http
pear.horde.org
Http_Client
Horde HTTP libraries
An API for making HTTP requests.
Chuck Hagenbuch
chuck
chuck@horde.org
yes
Jan Schneider
jan
jan@horde.org
yes
2013-08-27
2.0.4
1.2.0
stable
stable
BSD-2-Clause
* [jan] Provide more useful messages when throwing exceptions.
5.3.0
1.7.0
Horde_Exception
pear.horde.org
2.0.0
3.0.0alpha1
3.0.0alpha1
Horde_Support
pear.horde.org
2.0.0
3.0.0alpha1
3.0.0alpha1
Horde_Test
pear.horde.org
2.1.0
3.0.0alpha1
3.0.0alpha1
curl
http
1.0.0alpha1
1.0.0
alpha
alpha
2011-03-08
BSD-2-Clause
* First alpha release for Horde 4.
* Refactor to support multiple request transports, including Curl and the PECL http extension.
1.0.0beta1
1.0.0
beta
beta
2011-03-16
BSD-2-Clause
* First beta release for Horde 4.
1.0.0RC1
1.0.0
beta
beta
2011-03-22
BSD-2-Clause
* First release candidate for Horde 4.
1.0.0RC2
1.0.0
beta
beta
2011-03-29
BSD-2-Clause
* Second release candidate for Horde 4.
1.0.0
1.0.0
stable
stable
2011-04-06
BSD-2-Clause
* First stable release for Horde 4.
1.0.1
1.0.0
stable
stable
2011-06-01
BSD-2-Clause
* [cjh] Consistently implement configurable following of redirects (Bug #9898).
1.0.2
1.0.0
stable
stable
2011-06-01
BSD-2-Clause
* [jan] Fix regression with HTTP authentication.
1.0.3
1.0.0
stable
stable
2011-06-14
BSD-2-Clause
* [gwr] Allow setting request parameters on the existing client instance.
1.0.4
1.0.0
stable
stable
2011-10-18
BSD-2-Clause
* [gwr] Added SOCKS proxy support where available.
1.1.0
1.1.0
stable
stable
2011-11-02
BSD-2-Clause
* [gwr] Support multiple mock responses with the mock request.
* [gwr] Fixed setting response headers for the mock response.
1.1.1
1.1.0
stable
stable
2012-02-22
BSD-2-Clause
* [cjh] Fix infinite loop on unknown parameters being set.
* [cjh] Return real data for HTTP 4xx and 5xx responses when using fopen().
* [cjh] Fix setting PUT data in the Peclhttp Horde_Http_Request class.
2.0.0alpha1
1.1.0
alpha
stable
2012-07-05
BSD-2-Clause
* First alpha release for Horde 5.
2.0.0beta1
1.1.0
beta
stable
2012-07-19
BSD-2-Clause
* First beta release for Horde 5.
2.0.0beta2
1.2.0
beta
stable
2012-10-12
BSD-2-Clause
* [jan] Add verifyPeer request option to disable verification of certification peers during SSL request.
* [jan] Fix error handling in Fopen driver if a custom error handler is installed.
2.0.0
1.2.0
stable
stable
2012-10-30
BSD-2-Clause
* First stable release for Horde 5.
2.0.1
1.2.0
stable
stable
2012-11-19
BSD-2-Clause
* [mms] Use new Horde_Test layout.
2.0.2
1.2.0
stable
stable
2013-03-05
BSD-2-Clause
* [jan] Allow self-signed certificates when using the fopen driver.
2.0.3
1.2.0
stable
stable
2013-05-07
BSD-2-Clause
* [jan] Add configuration option to set User-Agent.
2.0.4
1.2.0
stable
stable
2013-08-27
BSD-2-Clause
* [jan] Provide more useful messages when throwing exceptions.
Horde_Http-2.0.4/doc/Horde/Http/examples/get-example-dot-com.php 0000664 0001750 0001750 00000000702 12207100265 022477 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
require 'Horde/Autoloader/Default.php';
$client = new Horde_Http_Client();
$response = $client->get('http://www.example.com/');
var_dump($response);
echo $response->getBody();
Horde_Http-2.0.4/doc/Horde/Http/COPYING 0000664 0001750 0001750 00000002430 12207100265 015433 0 ustar jan jan Copyright 1999-2013 Horde LLC. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Horde_Http-2.0.4/lib/Horde/Http/Request/Base.php 0000664 0001750 0001750 00000006146 12207100265 017424 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
/**
* @author Chuck Hagenbuch
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
abstract class Horde_Http_Request_Base
{
/**
* Request headers
* @var array
*/
protected $_headers = array();
/**
* @var array
*/
protected $_options = array();
/**
* Constructor
*/
public function __construct($options = array())
{
$this->setOptions($options);
}
public function setOptions($options = array())
{
$this->_options = array_merge($this->getDefaultOptions(), $options);
}
public function getDefaultOptions()
{
return array(
'uri' => null,
'method' => 'GET',
'data' => null,
'username' => '',
'password' => '',
'authenticationScheme' => Horde_Http::AUTH_ANY,
'proxyServer' => null,
'proxyPort' => null,
'proxyType' => Horde_Http::PROXY_HTTP,
'proxyUsername' => null,
'proxyPassword' => null,
'proxyAuthenticationScheme' => Horde_Http::AUTH_BASIC,
'redirects' => 5,
'timeout' => 5,
'userAgent' => str_replace(' @' . 'version@', '', 'Horde_Http 2.0.4'),
'verifyPeer' => true,
);
}
/**
* Send this HTTP request
*
* @return Horde_Http_Response_Base
*/
abstract public function send();
/**
* Get an adapter parameter
*
* @param string $name The parameter to get.
* @return mixed Parameter value.
*/
public function __get($name)
{
switch ($name) {
case 'headers':
return $this->_headers;
}
return isset($this->_options[$name]) ? $this->_options[$name] : null;
}
/**
* Set a request parameter
*
* @param string $name The parameter to set.
* @param mixed $value Parameter value.
*/
public function __set($name, $value)
{
switch ($name) {
case 'headers':
$this->setHeaders($value);
break;
}
$this->_options[$name] = $value;
}
/**
* Set one or more headers
*
* @param mixed $headers A hash of header + value pairs, or a single header name
* @param string $value A header value
*/
public function setHeaders($headers, $value = null)
{
if (!is_array($headers)) {
$headers = array($headers => $value);
}
foreach ($headers as $header => $value) {
$this->_headers[$header] = $value;
}
}
/**
* Get the current value of $header
*
* @param string $header Header name to get
* @return string $header's current value
*/
public function getHeader($header)
{
return isset($this->_headers[$header]) ? $this->_headers[$header] : null;
}
}
Horde_Http-2.0.4/lib/Horde/Http/Request/Curl.php 0000664 0001750 0001750 00000011364 12207100265 017455 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
/**
* @author Chuck Hagenbuch
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
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
*
* @throws Horde_Http_Exception
*/
public function __construct($args = array())
{
if (!extension_loaded('curl')) {
throw new Horde_Http_Exception('The curl extension is not installed. See http://php.net/curl.installation');
}
parent::__construct($args);
}
/**
* Send this HTTP request
*
* @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function send()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->uri);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $this->method);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
// User-Agent
curl_setopt($curl, CURLOPT_USERAGENT, $this->userAgent);
// Redirects
if ($this->redirects) {
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, $this->redirects);
} else {
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_MAXREDIRS, 0);
}
$data = $this->data;
if (is_array($data)) {
// If we don't set POSTFIELDS to a string, and the first value
// begins with @, it will be treated as a filename, and the proper
// POST data isn't passed.
$data = http_build_query($data);
}
if ($data) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
// Proxy settings
if ($this->proxyServer) {
curl_setopt($curl, CURLOPT_PROXY, $this->proxyServer);
if ($this->proxyPort) {
curl_setopt($curl, CURLOPT_PROXYPORT, $this->proxyPort);
}
if ($this->proxyUsername && $this->proxyPassword) {
curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->proxyUsername . ':' . $this->proxyPassword);
curl_setopt($curl, CURLOPT_PROXYAUTH, $this->_httpAuthScheme($this->proxyAuthenticationScheme));
}
if ($this->proxyType == Horde_Http::PROXY_SOCKS5) {
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
} else if ($this->proxyType != Horde_Http::PROXY_HTTP) {
throw new Horde_Http_Exception(sprintf('Proxy type %s not supported by this request type!', $this->proxyType));
}
}
// Authentication settings
if ($this->username) {
curl_setopt($curl, CURLOPT_USERPWD, $this->username . ':' . $this->password);
curl_setopt($curl, CURLOPT_HTTPAUTH, $this->_httpAuthScheme($this->authenticationScheme));
}
// Concatenate the headers
$hdr = array();
$headers = $this->headers;
if (empty($headers['Expect'])) {
$headers['Expect'] = '';
}
foreach ($headers as $header => $value) {
$hdr[] = $header . ': ' . $value;
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $hdr);
$result = curl_exec($curl);
if ($result === false) {
throw new Horde_Http_Exception(curl_error($curl), curl_errno($curl));
}
$info = curl_getinfo($curl);
return new Horde_Http_Response_Curl($this->uri, $result, $info);
}
/**
* Translate a Horde_Http::AUTH_* constant to CURLAUTH_*
*
* @param const
* @throws Horde_Http_Exception
* @return const
*/
protected function _httpAuthScheme($httpAuthScheme)
{
if (!isset($this->_httpAuthSchemes[$httpAuthScheme])) {
throw new Horde_Http_Exception('Unsupported authentication scheme (' . $httpAuthScheme . ')');
}
return $this->_httpAuthSchemes[$httpAuthScheme];
}
}
Horde_Http-2.0.4/lib/Horde/Http/Request/Factory.php 0000664 0001750 0001750 00000001766 12207100265 020164 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
/**
* @author Chuck Hagenbuch
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
class Horde_Http_Request_Factory
{
/**
* Find the best available request backend
*
* @return Horde_Http_Request_Base
*/
public function create()
{
if (class_exists('HttpRequest', false)) {
return new Horde_Http_Request_Peclhttp();
} elseif (extension_loaded('curl')) {
return new Horde_Http_Request_Curl();
} elseif (ini_get('allow_url_fopen')) {
return new Horde_Http_Request_Fopen();
} else {
throw new Horde_Http_Exception('No HTTP request backends are available. You must install pecl_http, curl, or enable allow_url_fopen.');
}
}
}
Horde_Http-2.0.4/lib/Horde/Http/Request/Fopen.php 0000664 0001750 0001750 00000011310 12207100265 017606 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
/**
* @author Chuck Hagenbuch
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Http
*/
class Horde_Http_Request_Fopen extends Horde_Http_Request_Base
{
/**
* Catched errors from the error handler.
*
* @var array
*/
protected $_errors = array();
/**
* Constructor
*
* @throws Horde_Http_Exception
*/
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);
}
/**
* Send this HTTP request
*
* @throws Horde_Http_Exception
* @return Horde_Http_Response_Base
*/
public function send()
{
$method = $this->method;
$uri = $this->uri;
$headers = $this->headers;
$data = $this->data;
if (is_array($data)) {
$data = http_build_query($data, '', '&');
}
$opts = array('http' => array());
// Proxy settings
if ($this->proxyServer) {
$opts['http']['proxy'] = 'tcp://' . $this->proxyServer;
if ($this->proxyPort) {
$opts['http']['proxy'] .= ':' . $this->proxyPort;
}
$opts['http']['request_fulluri'] = true;
if ($this->proxyUsername && $this->proxyPassword) {
// @TODO check $this->proxyAuthenticationScheme
$headers['Proxy-Authorization'] = 'Basic ' . base64_encode($this->proxyUsername . ':' . $this->proxyPassword);
}
if ($this->proxyType != Horde_Http::PROXY_HTTP) {
throw new Horde_Http_Exception(sprintf('Proxy type %s not supported by this request type!', $this->proxyType));
}
}
// Authentication settings
if ($this->username) {
switch ($this->authenticationScheme) {
case Horde_Http::AUTH_BASIC:
case Horde_Http::AUTH_ANY:
$headers['Authorization'] = 'Basic ' . base64_encode($this->username . ':' . $this->password);
break;
default:
throw new Horde_Http_Exception('Unsupported authentication scheme (' . $this->authenticationScheme . ')');
}
}
// Concatenate the headers
$hdr = array();
foreach ($headers as $header => $value) {
$hdr[] = $header . ': ' . $value;
}
// Stream context config.
$opts['http']['method'] = $method;
$opts['http']['header'] = implode("\n", $hdr);
$opts['http']['content'] = $data;
$opts['http']['timeout'] = $this->timeout;
$opts['http']['max_redirects'] = $this->redirects;
$opts['http']['ignore_errors'] = true;
$opts['http']['user_agent'] = $this->userAgent;
$opts['ssl']['verify_peer'] = $this->verifyPeer;
$opts['ssl']['allow_self_signed'] = true;
$context = stream_context_create($opts);
set_error_handler(array($this, '_errorHandler'), E_WARNING | E_NOTICE);
$stream = fopen($uri, 'rb', false, $context);
restore_error_handler();
if (!$stream) {
if (isset($this->_errors[0]['message']) &&
preg_match('/HTTP\/(\d+\.\d+) (\d{3}) (.*)$/', $this->_errors[0]['message'], $matches)) {
// Create a Response for the HTTP error code
return new Horde_Http_Response_Fopen($uri, null, $matches[0]);
} else {
throw new Horde_Http_Exception('Problem with ' . $uri . ': ' . implode('. ', array_reverse($this->_errors)));
}
}
$meta = stream_get_meta_data($stream);
$headers = isset($meta['wrapper_data']) ? $meta['wrapper_data'] : array();
return new Horde_Http_Response_Fopen($uri, $stream, $headers);
}
/**
* PHP error handler.
*
* @param integer $errno See set_error_handler().
* @param string $errstr See set_error_handler().
* @param string $errfile See set_error_handler().
* @param integer $errline See set_error_handler().
* @param array $errcontext See set_error_handler().
*/
protected function _errorHandler($errno, $errstr, $errfile, $errline,
$errcontext)
{
array_unshift($this->_errors, preg_replace('/^(.*?) \[