package.xml0000664000175000017500000004502112512754474011314 0ustar janjan 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 2015-04-13 2.1.5 1.3.0 stable stable BSD-2-Clause * [jan] Allow to pass Horde_Url objects as URI (Bug #13897). 5.3.0 6.0.0alpha1 6.0.0alpha1 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 pecl_http pecl.php.net 1.7.0 3.0.0alpha1 3.0.0alpha1 http curl 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. 2.0.5 1.2.0 stable stable 2014-02-24 BSD-2-Clause * [mms] Fopen driver needs to handle URIs without a protocol scheme - default to http (Bug #12991). 2.1.0 1.3.0 stable stable 2014-04-03 BSD-2-Clause * [jan] Add support for PECL http 2.0 extension (Michael Cramer <michael@bigmichi1.de>). 2.1.1 1.3.0 stable stable 2014-05-02 BSD-2-Clause * [jan] Fix HTTP authentication with PECL HTTP drivers. * [jan] Always cast reponse body to string with pecl_http 2.0 (Michael Cramer <michael@bigmichi1.de>). 2.1.2 1.3.0 stable stable 2014-12-29 BSD-2-Clause * [mms] Horde_Http_Base_Response#getHeader() is now case-insensitive for the header input (Bug #13736). 2.1.3 1.3.0 stable stable 2015-01-08 BSD-2-Clause * [jan] Add unit tests for PECL HTTP 1.x/2.x drivers. 2.1.4 1.3.0 stable stable 2015-03-03 BSD-2-Clause * [jan] Make Horde_Http_Base_Response::headers array keys lowercase again (Bug #13843). * [jan] Fix return code from multi-request actions in Peclhttp2 driver. 2.1.5 1.3.0 stable stable 2015-04-13 BSD-2-Clause * [jan] Allow to pass Horde_Url objects as URI (Bug #13897). Horde_Http-2.1.5/doc/Horde/Http/examples/get-example-dot-com.php0000664000175000017500000000070212512754474022521 0ustar janjan * @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.1.5/doc/Horde/Http/COPYING0000664000175000017500000000243012512754474015455 0ustar janjan Copyright 1999-2015 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.1.5/lib/Horde/Http/Request/Base.php0000664000175000017500000001102412512754474017435 0ustar janjan * @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 * * @property string|Horde_Url $uri Default URI if not specified for * individual requests. * @property array $headers Hash with additional request headers. * @property string $method Default request method if not specified * for individual requests. * @property array|string $data POST data fields or POST/PUT data body. * @property string $username Authentication user name. * @property string $password Authentication password. * @property string $authenticationScheme Authentication method, one of the * Horde_Http::AUTH_* constants. * @property string $proxyServer Host name of a proxy server. * @property integer $proxyPort Port number of a proxy server. * @property integer $proxyType Proxy server type, one of the * Horde_Http::PROXY_* constants. * @property string $proxyUsername Proxy authentication user name. * @property string $proxyPassword Proxy authentication password. * @property string $proxyAuthenticationScheme Proxy authentication method, * one of the Horde_Http::AUTH_* constants. * @property integer $redirects Maximum number of redirects to follow. * @property integer $timeout Timeout in seconds. * @property boolean $verifyPeer Verify SSL peer certificates? */ 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.1.5'), '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.1.5/lib/Horde/Http/Request/Curl.php0000664000175000017500000001140412512754474017472 0ustar janjan * @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, (string)$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((string)$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.1.5/lib/Horde/Http/Request/Factory.php0000664000175000017500000000214612512754474020177 0ustar janjan * @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 (class_exists('\http\Client', false)) { return new Horde_Http_Request_Peclhttp2(); } 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.1.5/lib/Horde/Http/Request/Fopen.php0000664000175000017500000001154612512754474017643 0ustar janjan * @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 = (string)$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 . ')'); } } // fopen() requires a protocol scheme if (parse_url($uri, PHP_URL_SCHEME) === null) { $uri = 'http://' . $uri; } // 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('/^(.*?) \[ * @author Gunnar Wrobel * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ /** * @author Chuck Hagenbuch * @author Gunnar Wrobel * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ class Horde_Http_Request_Mock extends Horde_Http_Request_Base { /** * Mock responses to return. * * @var array */ protected $_responses = array(); /** * Send this HTTP request * * @return Horde_Http_Response_Mock|NULL A response object or NULL in case * no responses has been set. */ public function send() { if (empty($this->_responses)) { return; } elseif (count($this->_responses) > 1) { return array_shift($this->_responses); } else { return $this->_responses[0]; } } /** * Set the HTTP response(s) to be returned by this adapter. This overwrites * any responses set before. * * @param Horde_Http_Response_Base $response */ public function setResponse(Horde_Http_Response_Base $response) { $this->_responses = array($response); } /** * Set the HTTP response(s) to be returned by this adapter as an array of strings. * * @param array $responses The responses to be added to the stack. * * @return NULL */ public function addResponses($responses) { foreach ($responses as $response) { if (is_string($response)) { $this->addResponse($response); } if (is_array($response)) { $this->addResponse( isset($response['body']) ? $response['body'] : '', isset($response['code']) ? $response['code'] : 200, isset($response['uri']) ? $response['uri'] : '', isset($response['headers']) ? $response['headers'] : array() ); } } } /** * Adds a response to the stack of responses. * * @param string|resourse $body The response body content. * @param string $code The response code. * @param string $uri The request uri. * @param array $headers Response headers. This can be one string * representing the whole header or an array * of strings with one string per header * line. * * @return Horde_Http_Response_Mock The response. */ public function addResponse( $body, $code = 200, $uri = '', $headers = array() ) { if (is_string($body)) { $stream = new Horde_Support_StringStream($body); $response = new Horde_Http_Response_Mock( $uri, $stream->fopen(), $headers ); } else { $response = new Horde_Http_Response_Mock($uri, $body, $headers); } $response->code = $code; $this->_responses[] = $response; } } Horde_Http-2.1.5/lib/Horde/Http/Request/PeclhttpBase.php0000664000175000017500000000722212512754474021146 0ustar janjan * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ /** * @author Michael Cramer * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ abstract class Horde_Http_Request_PeclhttpBase extends Horde_Http_Request_Base { /** * Map of HTTP authentication schemes from Horde_Http constants to * implementation specific constants. * * @var array */ protected $_httpAuthSchemes = array(); /** * Map of proxy types from Horde_Http to implementation specific constants. * * @var array */ protected $_proxyTypes = array(); /** * Constructor. * * @throws Horde_Http_Exception */ public function __construct($args = array()) { parent::__construct($args); } /** * Translates a Horde_Http::AUTH_* constant to implementation specific * constants. * * @param string $httpAuthScheme A Horde_Http::AUTH_* constant. * * @return const An implementation specific authentication scheme constant. * @throws Horde_Http_Exception */ protected function _httpAuthScheme($httpAuthScheme) { if (!isset($this->_httpAuthSchemes[$httpAuthScheme])) { throw new Horde_Http_Exception('Unsupported authentication scheme (' . $httpAuthScheme . ')'); } return $this->_httpAuthSchemes[$httpAuthScheme]; } /** * Translates a Horde_Http::PROXY_* constant to implementation specific * constants. * * @return const * @throws Horde_Http_Exception */ protected function _proxyType() { $proxyType = $this->proxyType; if (!isset($this->_proxyTypes[$proxyType])) { throw new Horde_Http_Exception('Unsupported proxy type (' . $proxyType . ')'); } return $this->_proxyTypes[$proxyType]; } /** * Generates the HTTP options for the request. * * @return array array with options * @throws Horde_Http_Exception */ protected function _httpOptions() { // Set options $httpOptions = array('headers' => $this->headers, 'redirect' => (int)$this->redirects, 'ssl' => array('verifypeer' => $this->verifyPeer), 'timeout' => $this->timeout, 'useragent' => $this->userAgent); // Proxy settings if ($this->proxyServer) { $httpOptions['proxyhost'] = $this->proxyServer; if ($this->proxyPort) { $httpOptions['proxyport'] = $this->proxyPort; } if ($this->proxyUsername && $this->proxyPassword) { $httpOptions['proxyauth'] = $this->proxyUsername . ':' . $this->proxyPassword; $httpOptions['proxyauthtype'] = $this->_httpAuthScheme($this->proxyAuthenticationScheme); } if ($this->proxyType == Horde_Http::PROXY_SOCKS4 || $this->proxyType == Horde_Http::PROXY_SOCKS5) { $httpOptions['proxytype'] = $this->_proxyType(); } 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) { $httpOptions['httpauth'] = $this->username . ':' . $this->password; $httpOptions['httpauthtype'] = $this->_httpAuthScheme($this->authenticationScheme); } return $httpOptions; } }Horde_Http-2.1.5/lib/Horde/Http/Request/Peclhttp.php0000664000175000017500000000457012512754474020356 0ustar janjan * @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_Peclhttp extends Horde_Http_Request_PeclhttpBase { /** * 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); } /** * Send this HTTP request * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function send() { if (!defined('HTTP_METH_' . $this->method)) { throw new Horde_Http_Exception('Method ' . $this->method . ' not supported.'); } $httpRequest = new HttpRequest((string)$this->uri, constant('HTTP_METH_' . $this->method)); $data = $this->data; if (is_array($data)) { $httpRequest->setPostFields($data); } else { if ($this->method == 'PUT') { $httpRequest->setPutData($data); } else { $httpRequest->setBody($data); } } $httpRequest->setOptions($this->_httpOptions()); try { $httpResponse = $httpRequest->send(); } catch (HttpException $e) { if (isset($e->innerException)){ throw new Horde_Http_Exception($e->innerException); } else { throw new Horde_Http_Exception($e); } } return new Horde_Http_Response_Peclhttp((string)$this->uri, $httpResponse); } } Horde_Http-2.1.5/lib/Horde/Http/Request/Peclhttp2.php0000664000175000017500000000500712512754474020434 0ustar janjan * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ /** * @author Michael Cramer * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ class Horde_Http_Request_Peclhttp2 extends Horde_Http_Request_PeclhttpBase { /** * Map of HTTP authentication schemes from Horde_Http constants to * HTTP_AUTH constants. * * @var array */ protected $_httpAuthSchemes = array( Horde_Http::AUTH_ANY => \http\Client\Curl\AUTH_ANY, Horde_Http::AUTH_BASIC => \http\Client\Curl\AUTH_BASIC, Horde_Http::AUTH_DIGEST => \http\Client\Curl\AUTH_DIGEST, Horde_Http::AUTH_GSSNEGOTIATE => \http\Client\Curl\AUTH_GSSNEG, Horde_Http::AUTH_NTLM => \http\Client\Curl\AUTH_NTLM, ); /** * Map of proxy types from Horde_Http to implementation specific constants. * @var array */ protected $_proxyTypes = array( Horde_Http::PROXY_SOCKS4 => \http\Client\Curl\PROXY_SOCKS4, Horde_Http::PROXY_SOCKS5 => \http\Client\Curl\PROXY_SOCKS5 ); /** * Constructor * * @throws Horde_Http_Exception */ public function __construct($args = array()) { if (!class_exists('\http\Client', false)) { throw new Horde_Http_Exception('The pecl_http extension is not installed. See http://php.net/http.install'); } parent::__construct($args); } /** * Send this HTTP request * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function send() { // at this time only the curl driver is supported $client = new \http\Client('curl'); $body = new \http\Message\Body(); $data = $this->data; if (is_array($data)) { $body->addForm($data); } else { $body->append($data); } $httpRequest = new \http\Client\Request($this->method, (string)$this->uri, $this->headers, $body); $client->setOptions($this->_httpOptions()); $client->enqueue($httpRequest); try { $client->send(); $httpResponse = $client->getResponse($httpRequest); } catch (\http\Exception $e) { throw new Horde_Http_Exception($e); } return new Horde_Http_Response_Peclhttp2((string)$this->uri, $httpResponse); } }Horde_Http-2.1.5/lib/Horde/Http/Response/Base.php0000664000175000017500000000776412512754474017623 0ustar janjan * @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_Response_Base { /** * Fetched URI. * * @var string */ public $uri; /** * HTTP protocol version that was used. * * @var float */ public $httpVersion; /** * HTTP response code. * * @var integer */ public $code; /** * Response headers. * * @var array */ public $headers; /** * Case-insensitive list of headers. * * @var Horde_Support_CaseInsensitiveArray */ protected $_headers; /** * Parses an array of response headers, mindful of line continuations, etc. * * @param array $headers * * @return array */ protected function _parseHeaders($headers) { if (!is_array($headers)) { $headers = preg_split("/\r?\n/", $headers); } $this->_headers = new Horde_Support_CaseInsensitiveArray(); $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. if (preg_match('/^HTTP\/(\d.\d) (\d{3})/', $headerLine, $httpMatches)) { $this->httpVersion = $httpMatches[1]; $this->code = (int)$httpMatches[2]; $this->_headers = new Horde_Support_CaseInsensitiveArray(); $lastHeader = null; } $headerLine = trim($headerLine, "\r\n"); if ($headerLine == '') { break; } if (preg_match('|^([\w-]+):\s+(.+)|', $headerLine, $m)) { $headerName = $m[1]; $headerValue = $m[2]; if ($tmp = $this->_headers[$headerName]) { if (!is_array($tmp)) { $tmp = array($tmp); } $tmp[] = $headerValue; $headerValue = $tmp; } $this->_headers[$headerName] = $headerValue; $lastHeader = $headerName; } elseif (preg_match("|^\s+(.+)$|", $headerLine, $m) && !is_null($lastHeader)) { if (is_array($this->_headers[$lastHeader])) { $tmp = $this->_headers[$lastHeader]; end($tmp); $tmp[key($tmp)] .= $m[1]; $this->_headers[$lastHeader] = $tmp; } else { $this->_headers[$lastHeader] .= $m[1]; } } } $this->headers = array_change_key_case($this->_headers->getArrayCopy()); } /** * Returns the body of the HTTP response. * * @throws Horde_Http_Exception * @return string HTTP response body. */ abstract public function getBody(); /** * Returns a stream pointing to the response body that can be used with all * standard PHP stream functions. */ public function getStream() { $string_body = $this->getBody(); $body = new Horde_Support_StringStream($string_body); return $body->fopen(); } /** * Returns the value of a single response header. * * @param string $header Header name to get ('Content-Type', * 'Content-Length', etc.). * * @return string HTTP header value. */ public function getHeader($header) { return $this->_headers[$header]; } } Horde_Http-2.1.5/lib/Horde/Http/Response/Curl.php0000664000175000017500000000424512512754474017645 0ustar janjan * @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_Response_Curl extends Horde_Http_Response_Base { /** * Info on the request obtained from curl_getinfo(). * * @var array */ protected $_info = array(); /** * Response body. * * @var string */ protected $_body; /** * Constructor. * * @param string $uri * @param string $curlresult * @param array $curlinfo */ public function __construct($uri, $curlresult, $curlinfo) { $this->uri = $uri; $this->_parseResult($curlresult); $this->_parseInfo($curlinfo); } /** * Returns the body of the HTTP response. * * @return string HTTP response body. */ public function getBody() { return $this->_body; } /** * Parses the combined header/body result from cURL. * * @param string $curlresult */ protected function _parseResult($curlresult) { /* Curl returns multiple headers, if the last action required multiple * requests, e.g. when doing Digest authentication. Only parse the * headers of the latest response. */ preg_match_all('/(^|\r\n\r\n)(HTTP\/)/', $curlresult, $matches, PREG_OFFSET_CAPTURE); $startOfHeaders = $matches[2][count($matches[2]) - 1][1]; $endOfHeaders = strpos($curlresult, "\r\n\r\n", $startOfHeaders); $headers = substr($curlresult, $startOfHeaders, $endOfHeaders - $startOfHeaders); $this->_parseHeaders($headers); $this->_body = substr($curlresult, $endOfHeaders + 4); } /** * Processes the results of curl_getinfo. * * @param array $curlinfo */ protected function _parseInfo($curlinfo) { $this->uri = $curlinfo['url']; $this->code = $curlinfo['http_code']; $this->_info = $curlinfo; } } Horde_Http-2.1.5/lib/Horde/Http/Response/Fopen.php0000664000175000017500000000335512512754474020010 0ustar janjan * @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_Response_Fopen extends Horde_Http_Response_Base { /** * Response body. * * @var stream */ protected $_stream; /** * Response content */ protected $_content; /** * Constructor. */ public function __construct($uri, $stream, $headers = array()) { $this->uri = $uri; $this->_stream = $stream; $this->_parseHeaders($headers); } /** * Returns the body of the HTTP response. * * @throws Horde_Http_Exception * @return string HTTP response body. */ public function getBody() { if (is_null($this->_content)) { $oldTrackErrors = ini_set('track_errors', 1); $content = @stream_get_contents($this->_stream); ini_set('track_errors', $oldTrackErrors); if ($content === false) { $msg = 'Problem reading data from ' . $this->uri; if (isset($php_errormsg)) { $msg .= ': ' . $php_errormsg; } throw new Horde_Http_Exception($msg); } $this->_content = $content; } return $this->_content; } /** * Returns a stream pointing to the response body that can be used with * all standard PHP stream functions. */ public function getStream() { return $this->_stream; } } Horde_Http-2.1.5/lib/Horde/Http/Response/Mock.php0000664000175000017500000000162312512754474017626 0ustar janjan * @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_Response_Mock extends Horde_Http_Response_Base { /** * Constructor */ public function __construct($uri, $stream, $headers = array()) { $this->uri = $uri; $this->_stream = $stream; $this->_parseHeaders($headers); } public function getBody() { $content = @stream_get_contents($this->_stream); if ($content === false) { throw new Horde_Http_Exception('Problem reading data from ' . $this->uri . ': ' . $php_errormsg); } return $content; } } Horde_Http-2.1.5/lib/Horde/Http/Response/Peclhttp.php0000664000175000017500000000253012512754474020516 0ustar janjan * @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_Response_Peclhttp extends Horde_Http_Response_Base { /** * HttpMessage object. * * @var HttpMessage */ protected $_message; /** * Constructor. * * @param string $uri * @param HttpMessage $message */ public function __construct($uri, HttpMessage $message) { try { $parent = $message->getParentMessage(); $location = $parent->getHeader('Location'); $this->uri = $location; } catch (HttpRuntimeException $e) { $this->uri = $uri; } $this->httpVersion = $message->getHttpVersion(); $this->code = $message->getResponseCode(); $this->_message = $message; $this->_headers = new Horde_Support_CaseInsensitiveArray( $message->getHeaders() ); $this->headers = array_change_key_case($this->_headers->getArrayCopy()); } public function getBody() { return $this->_message->getBody(); } } Horde_Http-2.1.5/lib/Horde/Http/Response/Peclhttp2.php0000664000175000017500000000274712512754474020612 0ustar janjan * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ /** * @author Michael Cramer * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ class Horde_Http_Response_Peclhttp2 extends Horde_Http_Response_Base { /** * HttpMessage object. * * @var \http\Client\Response */ protected $_response; /** * Constructor. * * @param string $uri * @param \http\Client\Response $response */ public function __construct($uri, \http\Client\Response $response) { try { $info = $response->getTransferInfo(); } catch (\http\Exception $e) { throw new Horde_Http_Exception($e); } try { $this->uri = $info->effective_url; } catch (\http\Exception\RuntimeException $e) { $this->uri = $uri; } $this->httpVersion = $response->getHttpVersion(); $this->code = $info->response_code; $this->_response = $response; $this->_headers = new Horde_Support_CaseInsensitiveArray( $response->getHeaders() ); $this->headers = array_change_key_case($this->_headers->getArrayCopy()); } public function getBody() { return $this->_response->getBody()->toString(); } } Horde_Http-2.1.5/lib/Horde/Http/Client.php0000664000175000017500000002163112512754474016356 0ustar janjan * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ /** * An HTTP client. * * @author Chuck Hagenbuch * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http * * @property boolean $httpMethodOverride * @see $_httpMethodOverride * @property Horde_Http_Request_Base $request * A concrete request instance. * @property-write string|Horde_Url $request.uri * Default URI if not specified for individual * requests. * @property-write array $request.headers * Hash with additional request headers. * @property-write string $request.method * Default request method if not specified for * individual requests. * @property-write array|string $request.data * POST data fields or POST/PUT data body. * @property-write string $request.username * Authentication user name. * @property-write string $request.password * Authentication password. * @property-write string $request.authenticationScheme * Authentication method, one of the * Horde_Http::AUTH_* constants. * @property-write string $request.proxyServer * Host name of a proxy server. * @property-write integer $request.proxyPort * Port number of a proxy server. * @property-write integer $request.proxyType * Proxy server type, one of the * Horde_Http::PROXY_* constants. * @property-write string $request.proxyUsername * Proxy authentication user name. * @property-write string $request.proxyPassword * Proxy authentication password. * @property-write string $request.proxyAuthenticationScheme * Proxy authentication method, one of the * Horde_Http::AUTH_* constants. * @property-write integer $request.redirects * Maximum number of redirects to follow. * @property-write integer $request.timeout * Timeout in seconds. * @property-write boolean $request.verifyPeer * Verify SSL peer certificates? */ class Horde_Http_Client { /** * The current HTTP request. * * @var Horde_Http_Request_Base */ protected $_request; /** * The previous HTTP request. * * @var Horde_Http_Request_Base */ protected $_lastRequest; /** * The most recent HTTP response. * * @var Horde_Http_Response_Base */ protected $_lastResponse; /** * Use POST instead of PUT and DELETE, sending X-HTTP-Method-Override with * the intended method name instead. * * @var boolean */ protected $_httpMethodOverride = false; /** * Horde_Http_Client constructor. * * @param array $args Any Http_Client settings to initialize in the * constructor. See the class properties for available * settings. */ public function __construct($args = array()) { // Set or create request object if (isset($args['request'])) { $this->_request = $args['request']; unset($args['request']); } else { $requestFactory = new Horde_Http_Request_Factory(); $this->_request = $requestFactory->create(); } foreach ($args as $key => $val) { $this->$key = $val; } } /** * Sends a GET request. * * @param string $uri Request URI. * @param array $headers Additional request headers. * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function get($uri = null, $headers = array()) { return $this->request('GET', $uri, null, $headers); } /** * Sends a POST request. * * @param string $uri Request URI. * @param array|string $data Data fields or data body. * @param array $headers Additional request headers. * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function post($uri = null, $data = null, $headers = array()) { return $this->request('POST', $uri, $data, $headers); } /** * Sends a PUT request. * * @param string $uri Request URI. * @param string $data Data body. * @param array $headers Additional request headers. * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function put($uri = null, $data = null, $headers = array()) { if ($this->_httpMethodOverride) { $headers = array_merge( array('X-HTTP-Method-Override' => 'PUT'), $headers ); return $this->post($uri, $data, $headers); } return $this->request('PUT', $uri, $data, $headers); } /** * Sends a DELETE request. * * @param string $uri Request URI. * @param array $headers Additional request headers. * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function delete($uri = null, $headers = array()) { if ($this->_httpMethodOverride) { $headers = array_merge( array('X-HTTP-Method-Override' => 'DELETE'), $headers ); return $this->post($uri, null, $headers); } return $this->request('DELETE', $uri, null, $headers); } /** * Sends a HEAD request. * * @param string $uri Request URI. * @param array $headers Additional request headers. * * @throws Horde_Http_Exception * @return Horde_Http_Response_Base */ public function head($uri = null, $headers = array()) { return $this->request('HEAD', $uri, null, $headers); } /** * Sends an HTTP request. * * @param string $method HTTP request method (GET, PUT, etc.) * @param string|Horde_Url $uri URI to request, if different from * $this->uri * @param string|array $data Request data. 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() ) { if ($method !== null) { $this->request->method = $method; } if ($uri !== null) { $this->request->uri = $uri; } if ($data !== null) { $this->request->data = $data; } if (count($headers)) { $this->request->setHeaders($headers); } $this->_lastRequest = $this->_request; $this->_lastResponse = $this->_request->send(); return $this->_lastResponse; } /** * Returns a client parameter. * * @param string $name The parameter to return. * * @return mixed The parameter value. */ public function __get($name) { return isset($this->{'_' . $name}) ? $this->{'_' . $name} : null; } /** * Sets a client parameter. * * @param string $name The parameter to set. * @param mixed $value The parameter value. */ public function __set($name, $value) { if ((strpos($name, '.') === false)) { if (isset($this->{'_' . $name})) { $this->{'_' . $name} = $value; return true; } else { throw new Horde_Http_Exception('unknown parameter: "' . $name . '"'); } } list($object, $objectkey) = explode('.', $name, 2); if ($object == 'request') { $this->$object->$objectkey = $value; return true; } elseif ($object == 'client') { $objectKey = '_' . $objectKey; $this->$objectKey = $value; return true; } throw new Horde_Http_Exception('unknown parameter: "' . $name . '"'); } } Horde_Http-2.1.5/lib/Horde/Http/Exception.php0000664000175000017500000000064012512754474017073 0ustar janjan * @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_Exception extends Horde_Exception_Wrapped { } Horde_Http-2.1.5/lib/Horde/Http.php0000664000175000017500000000132412512754474015135 0ustar janjan * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package Http */ /** * Constants * * @author Chuck Hagenbuch * @license http://www.horde.org/licenses/bsd BSD * @category Horde * @package 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'; /** * Proxy types */ const PROXY_HTTP = 0; const PROXY_SOCKS4 = 1; const PROXY_SOCKS5 = 2; } Horde_Http-2.1.5/test/Horde/Http/AllTests.php0000664000175000017500000000013212512754474017075 0ustar janjanrun(); Horde_Http-2.1.5/test/Horde/Http/bootstrap.php0000664000175000017500000000014312512754474017361 0ustar janjanassertEquals(5, $request->timeout); } public function testSetTimeout() { $request = new Horde_Http_Request_Mock(); $client = new Horde_Http_Client( array('request' => $request) ); $client->{'request.timeout'} = 10; $this->assertEquals(10, $request->timeout); } /** * @expectedException Horde_Http_Exception */ public function testSetUnknownOption() { $request = new Horde_Http_Request_Mock(); $client = new Horde_Http_Client( array('request' => $request) ); $client->timeout = 10; } } Horde_Http-2.1.5/test/Horde/Http/conf.php.dist0000664000175000017500000000006112512754474017232 0ustar janjanmarkTestSkipped('Missing PHP extension "curl"!'); } parent::setUp(); } } Horde_Http-2.1.5/test/Horde/Http/FopenTest.php0000664000175000017500000000132212512754474017253 0ustar janjan_skipMissingConfig(); $client = new Horde_Http_Client(array( 'request' => new Horde_Http_Request_Fopen() )); $response = $client->get($this->_server . '/doesntexist'); $body = $response->getBody(); $this->assertTrue(strlen($body) > 0); } } Horde_Http-2.1.5/test/Horde/Http/MockTest.php0000664000175000017500000000701412512754474017101 0ustar janjan * @license http://www.horde.org/licenses/bsd * @link http://www.horde.org/libraries/Horde_Http */ /** * Test the remote server handler. * * PHP version 5 * * @category Horde * @package Http * @subpackage UnitTests * @author Gunnar Wrobel * @license http://www.horde.org/licenses/bsd * @link http://www.horde.org/libraries/Horde_Http */ class Horde_Http_MockTest extends PHPUnit_Framework_TestCase { public function testNoResponses() { $mock = new Horde_Http_Request_Mock(); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertNull($client->get()); } public function testPreparedResponse() { $body = 'Test'; $stream = new Horde_Support_StringStream($body); $response = new Horde_Http_Response_Mock('', $stream->fopen()); $mock = new Horde_Http_Request_Mock(); $mock->setResponse($response); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertEquals('Test', $client->get()->getBody()); } public function testAddResponseBody() { $mock = new Horde_Http_Request_Mock(); $mock->addResponse('Test'); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertEquals('Test', $client->get()->getBody()); } public function testAddResponseCode() { $mock = new Horde_Http_Request_Mock(); $mock->addResponse('Test', 404); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertEquals(404, $client->get()->code); } public function testAddResponseUri() { $mock = new Horde_Http_Request_Mock(); $mock->addResponse('Test', 404, 'http://example.org'); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertEquals('http://example.org', $client->get()->uri); } public function testAddResponseHeader() { $mock = new Horde_Http_Request_Mock(); $mock->addResponse('Test', 404, 'http://example.org', array('Test: TEST')); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertEquals('TEST', $client->get()->getHeader('test')); $this->assertEquals(array('test' => 'TEST'), $client->get()->headers); } public function testAddStringResponses() { $mock = new Horde_Http_Request_Mock(); $mock->addResponses(array('A', 'B')); $client = new Horde_Http_Client(array('request' => $mock)); $client->get(); $this->assertEquals('B', $client->get()->getBody()); } public function testAddArrayResponses() { $mock = new Horde_Http_Request_Mock(); $mock->addResponses( array( array('body' => 'A'), array('code' => 404), array('uri' => 'http://example.org'), array('headers' => 'Test: TEST'), ) ); $client = new Horde_Http_Client(array('request' => $mock)); $this->assertEquals('A', $client->get()->getBody()); $this->assertEquals(404, $client->get()->code); $this->assertEquals('http://example.org', $client->get()->uri); $this->assertEquals('TEST', $client->get()->getHeader('test')); $this->assertEquals(array('test' => 'TEST'), $client->get()->headers); } } Horde_Http-2.1.5/test/Horde/Http/Peclhttp2Test.php0000664000175000017500000000121212512754474020047 0ustar janjanmarkTestSkipped('Missing PHP extension "http" or wrong version!'); } parent::setUp(); } } Horde_Http-2.1.5/test/Horde/Http/PeclhttpTest.php0000664000175000017500000000121012512754474017763 0ustar janjanmarkTestSkipped('Missing PHP extension "http" or wrong version!'); } parent::setUp(); } } Horde_Http-2.1.5/test/Horde/Http/phpunit.xml0000664000175000017500000000030612512754474017045 0ustar janjan ../../../lib Horde_Http-2.1.5/test/Horde/Http/TestBase.php0000664000175000017500000000721412512754474017064 0ustar janjan_server = $config['http']['server']; } } public function testRequest() { $this->_skipMissingConfig(); $client = new Horde_Http_Client( array('request' => new self::$_requestClass()) ); $response = $client->get('http://' . $this->_server); $this->assertStringStartsWith('http', $response->uri); $this->assertStringStartsWith('1.', $response->httpVersion); $this->assertEquals(200, $response->code); $this->assertInternalType('array', $response->headers); $this->assertInternalType('string', $response->getBody()); $this->assertGreaterThan(0, strlen($response->getBody())); $this->assertInternalType('resource', $response->getStream()); $this->assertStringMatchesFormat( '%s/%s', $response->getHeader('Content-Type') ); $this->assertEquals( $response->getHeader('content-type'), $response->getHeader('Content-Type') ); $this->assertArrayHasKey('content-type', $response->headers); $this->assertEquals( $response->getHeader('content-type'), $response->headers['content-type'] ); } /** * @expectedException Horde_Http_Exception */ public function testThrowsOnBadUri() { $client = new Horde_Http_Client( array('request' => new self::$_requestClass()) ); $client->get('http://doesntexist/'); } /** * @expectedException Horde_Http_Exception */ public function testThrowsOnInvalidProxyType() { $client = new Horde_Http_Client( array( 'request' => new self::$_requestClass( array( 'proxyServer' => 'localhost', 'proxyType' => Horde_Http::PROXY_SOCKS4 ) ) ) ); $client->get('http://www.example.com/'); } public function testReturnsResponseInsteadOfExceptionOn404() { $this->_skipMissingConfig(); $client = new Horde_Http_Client( array('request' => new self::$_requestClass()) ); $response = $client->get('http://' . $this->_server . '/doesntexist'); $this->assertEquals(404, $response->code); } public function testGetBodyAfter404() { $this->_skipMissingConfig(); $client = new Horde_Http_Client( array('request' => new self::$_requestClass()) ); $response = $client->get('http://' . $this->_server . '/doesntexist'); $content = $response->getBody(); $this->assertGreaterThan(0, strlen($content)); } protected function _skipMissingConfig() { if (empty($this->_server)) { $this->markTestSkipped('Missing configuration!'); } } }