import v1.1.0_RC2 | 2009-09-20

This commit is contained in:
2019-07-17 22:19:00 +02:00
parent 3b7ba80568
commit 38c146901c
2504 changed files with 101817 additions and 62316 deletions

View File

@ -16,8 +16,8 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @version $Id: Curl.php 14379 2009-03-19 14:57:23Z matthew $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Curl.php 17118 2009-07-26 09:41:41Z shahar $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@ -34,7 +34,7 @@ require_once 'Zend/Http/Client/Adapter/Interface.php';
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interface
@ -62,7 +62,7 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
/**
* List of cURL options that should never be overwritten
*
*
* @var array
*/
protected $_invalidOverwritableCurlOptions = array(
@ -110,18 +110,39 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
* Set the configuration array for the adapter
*
* @throws Zend_Http_Client_Adapter_Exception
* @param array $config
* @param Zend_Config | array $config
* @return Zend_Http_Client_Adapter_Curl
*/
public function setConfig($config = array())
{
if (!is_array($config)) {
if ($config instanceof Zend_Config) {
$config = $config->toArray();
} elseif (! is_array($config)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Http Adapter configuration expects an array, ' . gettype($config) . ' recieved.');
throw new Zend_Http_Client_Adapter_Exception(
'Array or Zend_Config object expected, got ' . gettype($config)
);
}
if(isset($config['proxy_user']) && isset($config['proxy_pass'])) {
$this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxy_user'].":".$config['proxy_pass']);
unset($config['proxy_user'], $config['proxy_pass']);
}
foreach ($config as $k => $v) {
$this->_config[strtolower($k)] = $v;
$option = strtolower($k);
switch($option) {
case 'proxy_host':
$this->setCurlOption(CURLOPT_PROXY, $v);
break;
case 'proxy_port':
$this->setCurlOption(CURLOPT_PROXYPORT, $v);
break;
default:
$this->_config[$option] = $v;
break;
}
}
return $this;
@ -129,7 +150,7 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
/**
* Direct setter for cURL adapter related options.
*
*
* @param string|int $option
* @param mixed $value
* @return Zend_Http_Adapter_Curl
@ -160,9 +181,9 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
}
// If we are connected to a different server or port, disconnect first
if ($this->_curl
&& is_array($this->_connected_to)
&& ($this->_connected_to[0] != $host
if ($this->_curl
&& is_array($this->_connected_to)
&& ($this->_connected_to[0] != $host
|| $this->_connected_to[1] != $port)
) {
$this->close();
@ -389,4 +410,14 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
$this->_curl = null;
$this->_connected_to = array(null, null);
}
/**
* Get cUrl Handle
*
* @return resource
*/
public function getHandle()
{
return $this->_curl;
}
}

View File

@ -15,19 +15,24 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter_Exception
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 17118 2009-07-26 09:41:41Z shahar $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Http_Client_Exception
*/
require_once 'Zend/Http/Client/Exception.php';
/**
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Http_Client_Adapter_Exception extends Zend_Http_Client_Exception
{}
{
const READ_TIMEOUT = 1000;
}

View File

@ -16,8 +16,8 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @version $Id: Interface.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Interface.php 16214 2009-06-21 19:34:03Z thomas $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@ -30,7 +30,7 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Zend_Http_Client_Adapter_Interface

View File

@ -16,13 +16,22 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @version $Id: Proxy.php 12504 2008-11-10 16:28:46Z matthew $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Proxy.php 17118 2009-07-26 09:41:41Z shahar $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Uri_Http
*/
require_once 'Zend/Uri/Http.php';
/**
* @see Zend_Http_Client
*/
require_once 'Zend/Http/Client.php';
/**
* @see Zend_Http_Client_Adapter_Socket
*/
require_once 'Zend/Http/Client/Adapter/Socket.php';
/**
@ -37,7 +46,7 @@ require_once 'Zend/Http/Client/Adapter/Socket.php';
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
@ -49,6 +58,8 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
*/
protected $config = array(
'ssltransport' => 'ssl',
'sslcert' => null,
'sslpassphrase' => null,
'proxy_host' => '',
'proxy_port' => 8080,
'proxy_user' => '',
@ -63,7 +74,7 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
* @var boolean
*/
protected $negotiated = false;
/**
* Connect to the remote server
*
@ -73,41 +84,20 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
* @param string $host
* @param int $port
* @param boolean $secure
* @param int $timeout
*/
public function connect($host, $port = 80, $secure = false)
{
// If no proxy is set, fall back to Socket adapter
if (! $this->config['proxy_host']) return parent::connect($host, $port, $secure);
// Go through a proxy - the connection is actually to the proxy server
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
// If we are connected to the wrong proxy, disconnect first
if (($this->connected_to[0] != $host || $this->connected_to[1] != $port)) {
if (is_resource($this->socket)) $this->close();
if (! $this->config['proxy_host']) {
return parent::connect($host, $port, $secure);
}
// Now, if we are not connected, connect
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
$this->socket = @fsockopen($host, $port, $errno, $errstr, (int) $this->config['timeout']);
if (! $this->socket) {
$this->close();
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'Unable to Connect to proxy server ' . $host . ':' . $port . '. Error #' . $errno . ': ' . $errstr);
}
// Set the stream timeout
if (!stream_set_timeout($this->socket, (int) $this->config['timeout'])) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception('Unable to set the connection timeout');
}
// Update connected_to
$this->connected_to = array($host, $port);
}
// Connect (a non-secure connection) to the proxy server
return parent::connect(
$this->config['proxy_host'],
$this->config['proxy_port'],
false
);
}
/**
@ -134,7 +124,7 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
$host = $this->config['proxy_host'];
$port = $this->config['proxy_port'];
if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
if ($this->connected_to[0] != "tcp://$host" || $this->connected_to[1] != $port) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong proxy server");
}
@ -145,18 +135,26 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
$this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
);
}
// if we are proxying HTTPS, preform CONNECT handshake with the proxy
if ($uri->getScheme() == 'https' && (! $this->negotiated)) {
$this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
$this->negotiated = true;
}
// Save request method for later
$this->method = $method;
// Build request headers
$request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
if ($this->negotiated) {
$path = $uri->getPath();
if ($uri->getQuery()) {
$path .= '?' . $uri->getQuery();
}
$request = "$method $path HTTP/$http_ver\r\n";
} else {
$request = "$method $uri HTTP/$http_ver\r\n";
}
// Add all headers to the request string
foreach ($headers as $k => $v) {
@ -186,21 +184,21 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
*/
protected function connectHandshake($host, $port = 443, $http_ver = '1.1', array &$headers = array())
{
$request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
$request = "CONNECT $host:$port HTTP/$http_ver\r\n" .
"Host: " . $this->config['proxy_host'] . "\r\n";
// Add the user-agent header
if (isset($this->config['useragent'])) {
$request .= "User-agent: " . $this->config['useragent'] . "\r\n";
}
// If the proxy-authorization header is set, send it to proxy but remove
// it from headers sent to target host
if (isset($headers['proxy-authorization'])) {
$request .= "Proxy-authorization: " . $headers['proxy-authorization'] . "\r\n";
unset($headers['proxy-authorization']);
}
$request .= "\r\n";
// Send the request
@ -219,35 +217,35 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
if (!chop($line)) break;
}
}
// Check that the response from the proxy is 200
if (Zend_Http_Response::extractCode($response) != 200) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Unable to connect to HTTPS proxy. Server response: " . $response);
}
// If all is good, switch socket to secure mode. We have to fall back
// through the different modes
// through the different modes
$modes = array(
STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_TLS_CLIENT,
STREAM_CRYPTO_METHOD_SSLv3_CLIENT,
STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
STREAM_CRYPTO_METHOD_SSLv2_CLIENT
);
$success = false;
$success = false;
foreach($modes as $mode) {
$success = stream_socket_enable_crypto($this->socket, true, $mode);
if ($success) break;
}
if (! $success) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception("Unable to connect to" .
throw new Zend_Http_Client_Adapter_Exception("Unable to connect to" .
" HTTPS server through proxy: could not negotiate secure connection.");
}
}
/**
* Close the connection to the server
*
@ -257,7 +255,7 @@ class Zend_Http_Client_Adapter_Proxy extends Zend_Http_Client_Adapter_Socket
parent::close();
$this->negotiated = false;
}
/**
* Destructor: make sure the socket is disconnected
*

View File

@ -16,12 +16,18 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @version $Id: Socket.php 13013 2008-12-04 12:04:24Z yoshida@zend.co.jp $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Socket.php 17124 2009-07-26 09:46:42Z shahar $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Uri_Http
*/
require_once 'Zend/Uri/Http.php';
/**
* @see Zend_Http_Client_Adapter_Interface
*/
require_once 'Zend/Http/Client/Adapter/Interface.php';
/**
@ -31,7 +37,7 @@ require_once 'Zend/Http/Client/Adapter/Interface.php';
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interface
@ -69,6 +75,13 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
*/
protected $method = null;
/**
* Stream context
*
* @var resource
*/
protected $_context = null;
/**
* Adapter constructor, currently empty. Config is set using setConfig()
*
@ -80,14 +93,18 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
/**
* Set the configuration array for the adapter
*
* @param array $config
* @param Zend_Config | array $config
*/
public function setConfig($config = array())
{
if (! is_array($config)) {
if ($config instanceof Zend_Config) {
$config = $config->toArray();
} elseif (! is_array($config)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'$concig expects an array, ' . gettype($config) . ' recieved.');
'Array or Zend_Config object expected, got ' . gettype($config)
);
}
foreach ($config as $k => $v) {
@ -95,13 +112,60 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
}
}
/**
* Set the stream context for the TCP connection to the server
*
* Can accept either a pre-existing stream context resource, or an array
* of stream options, similar to the options array passed to the
* stream_context_create() PHP function. In such case a new stream context
* will be created using the passed options.
*
* @since Zend Framework 1.9
*
* @param mixed $context Stream context or array of context options
* @return Zend_Http_Client_Adapter_Socket
*/
public function setStreamContext($context)
{
if (is_resource($context) && get_resource_type($context) == 'stream-context') {
$this->_context = $context;
} elseif (is_array($context)) {
$this->_context = stream_context_create($context);
} else {
// Invalid parameter
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
"Expecting either a stream context resource or array, got " . gettype($context)
);
}
return $this;
}
/**
* Get the stream context for the TCP connection to the server.
*
* If no stream context is set, will create a default one.
*
* @return resource
*/
public function getStreamContext()
{
if (! $this->_context) {
$this->_context = stream_context_create();
}
return $this->_context;
}
/**
* Connect to the remote server
*
* @param string $host
* @param int $port
* @param boolean $secure
* @param int $timeout
*/
public function connect($host, $port = 80, $secure = false)
{
@ -115,7 +179,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
// Now, if we are not connected, connect
if (! is_resource($this->socket) || ! $this->config['keepalive']) {
$context = stream_context_create();
$context = $this->getStreamContext();
if ($secure) {
if ($this->config['sslcert'] !== null) {
if (! stream_context_set_option($context, 'ssl', 'local_cert',
@ -142,6 +206,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
(int) $this->config['timeout'],
$flags,
$context);
if (! $this->socket) {
$this->close();
require_once 'Zend/Http/Client/Adapter/Exception.php';
@ -219,6 +284,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
// First, read headers only
$response = '';
$gotStatus = false;
while (($line = @fgets($this->socket)) !== false) {
$gotStatus = $gotStatus || (strpos($line, 'HTTP') !== false);
if ($gotStatus) {
@ -227,26 +293,39 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
}
}
$this->_checkSocketReadTimeout();
$statusCode = Zend_Http_Response::extractCode($response);
// Handle 100 and 101 responses internally by restarting the read again
if ($statusCode == 100 || $statusCode == 101) return $this->read();
// Check headers to see what kind of connection / transfer encoding we have
$headers = Zend_Http_Response::extractHeaders($response);
/**
* Responses to HEAD requests and 204 or 304 responses are not expected
* to have a body - stop reading here
*/
if ($statusCode == 304 || $statusCode == 204 ||
$this->method == Zend_Http_Client::HEAD) return $response;
$this->method == Zend_Http_Client::HEAD) {
// Check headers to see what kind of connection / transfer encoding we have
$headers = Zend_Http_Response::extractHeaders($response);
// Close the connection if requested to do so by the server
if (isset($headers['connection']) && $headers['connection'] == 'close') {
$this->close();
}
return $response;
}
// If we got a 'transfer-encoding: chunked' header
if (isset($headers['transfer-encoding'])) {
if ($headers['transfer-encoding'] == 'chunked') {
if (strtolower($headers['transfer-encoding']) == 'chunked') {
do {
$line = @fgets($this->socket);
$this->_checkSocketReadTimeout();
$chunk = $line;
// Figure out the next chunk size
@ -261,60 +340,70 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
// Convert the hexadecimal value to plain integer
$chunksize = hexdec($chunksize);
// Read chunk
$left_to_read = $chunksize;
while ($left_to_read > 0) {
$line = @fread($this->socket, $left_to_read);
if ($line === false || strlen($line) === 0)
{
// Read next chunk
$read_to = ftell($this->socket) + $chunksize;
do {
$current_pos = ftell($this->socket);
if ($current_pos >= $read_to) break;
$line = @fread($this->socket, $read_to - $current_pos);
if ($line === false || strlen($line) === 0) {
$this->_checkSocketReadTimeout();
break;
} else {
$chunk .= $line;
$left_to_read -= strlen($line);
}
// Break if the connection ended prematurely
if (feof($this->socket)) break;
}
} while (! feof($this->socket));
$chunk .= @fgets($this->socket);
$this->_checkSocketReadTimeout();
$response .= $chunk;
} while ($chunksize > 0);
} else {
$this->close();
throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' .
$headers['transfer-encoding'] . '" transfer encoding');
}
// Else, if we got the content-length header, read this number of bytes
} elseif (isset($headers['content-length'])) {
$left_to_read = $headers['content-length'];
$current_pos = ftell($this->socket);
$chunk = '';
while ($left_to_read > 0) {
$chunk = @fread($this->socket, $left_to_read);
if ($chunk === false || strlen($chunk) === 0)
{
for ($read_to = $current_pos + $headers['content-length'];
$read_to > $current_pos;
$current_pos = ftell($this->socket)) {
$chunk = @fread($this->socket, $read_to - $current_pos);
if ($chunk === false || strlen($chunk) === 0) {
$this->_checkSocketReadTimeout();
break;
} else {
$left_to_read -= strlen($chunk);
$response .= $chunk;
}
$response .= $chunk;
// Break if the connection ended prematurely
if (feof($this->socket)) break;
}
// Fallback: just read the response until EOF
} else {
do {
$buff = @fread($this->socket, 8192);
if ($buff === false || strlen($buff) === 0)
{
break;
} else {
do {
$buff = @fread($this->socket, 8192);
if ($buff === false || strlen($buff) === 0) {
$this->_checkSocketReadTimeout();
break;
} else {
$response .= $buff;
}
} while (feof($this->socket) === false);
}
} while (feof($this->socket) === false);
$this->close();
}
@ -338,6 +427,28 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
$this->connected_to = array(null, null);
}
/**
* Check if the socket has timed out - if so close connection and throw
* an exception
*
* @throws Zend_Http_Client_Adapter_Exception with READ_TIMEOUT code
*/
protected function _checkSocketReadTimeout()
{
if ($this->socket) {
$info = stream_get_meta_data($this->socket);
$timedout = $info['timed_out'];
if ($timedout) {
$this->close();
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
"Read timed out after {$this->config['timeout']} seconds",
Zend_Http_Client_Adapter_Exception::READ_TIMEOUT
);
}
}
}
/**
* Destructor: make sure the socket is disconnected
*

View File

@ -15,13 +15,22 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @version $Id: Test.php 12104 2008-10-23 22:36:28Z shahar $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Test.php 17118 2009-07-26 09:41:41Z shahar $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Uri_Http
*/
require_once 'Zend/Uri/Http.php';
/**
* @see Zend_Http_Response
*/
require_once 'Zend/Http/Response.php';
/**
* @see Zend_Http_Client_Adapter_Interface
*/
require_once 'Zend/Http/Client/Adapter/Interface.php';
/**
@ -35,7 +44,7 @@ require_once 'Zend/Http/Client/Adapter/Interface.php';
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Http_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interface
@ -72,14 +81,18 @@ class Zend_Http_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interfac
/**
* Set the configuration array for the adapter
*
* @param array $config
* @param Zend_Config | array $config
*/
public function setConfig($config = array())
{
if (! is_array($config)) {
if ($config instanceof Zend_Config) {
$config = $config->toArray();
} elseif (! is_array($config)) {
require_once 'Zend/Http/Client/Adapter/Exception.php';
throw new Zend_Http_Client_Adapter_Exception(
'$config expects an array, ' . gettype($config) . ' recieved.');
'Array or Zend_Config object expected, got ' . gettype($config)
);
}
foreach ($config as $k => $v) {
@ -87,6 +100,7 @@ class Zend_Http_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interfac
}
}
/**
* Connect to the remote server
*
@ -158,7 +172,7 @@ class Zend_Http_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interfac
public function setResponse($response)
{
if ($response instanceof Zend_Http_Response) {
$response = $response->asString();
$response = $response->asString("\r\n");
}
$this->responses = (array)$response;
@ -168,10 +182,14 @@ class Zend_Http_Client_Adapter_Test implements Zend_Http_Client_Adapter_Interfac
/**
* Add another response to the response buffer.
*
* @param string $response
* @param string Zend_Http_Response|$response
*/
public function addResponse($response)
{
if ($response instanceof Zend_Http_Response) {
$response = $response->asString("\r\n");
}
$this->responses[] = $response;
}

View File

@ -15,18 +15,21 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Exception
* @version $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 16872 2009-07-20 11:47:08Z mikaelkael $
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* @see Zend_Http_Exception
*/
require_once 'Zend/Http/Exception.php';
/**
* @category Zend
* @package Zend_Http
* @subpackage Client
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Http_Client_Exception extends Zend_Http_Exception