Skip to content

Commit

Permalink
[Http] Fix broken Client
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed May 7, 2012
1 parent a4af63e commit 4119467
Showing 1 changed file with 24 additions and 32 deletions.
56 changes: 24 additions & 32 deletions Zend/Http/Client.php
Expand Up @@ -23,15 +23,7 @@
use ArrayIterator,
Zend\Config\Config,
Zend\Uri\Http,
Zend\Http\Header\Cookie,
Zend\Http\Header\SetCookie,
Zend\Http\Request as HttpRequest,
Zend\Http\Response as HttpResponse,
Zend\Http\Response\Stream as HttpResponseStream,
Zend\Stdlib\Parameters,
Zend\Stdlib\DispatchableInterface as Dispatchable,
Zend\Stdlib\RequestInterface as Request,
Zend\Stdlib\ResponseInterface as Response;
Zend\Stdlib;

/**
* Http client
Expand All @@ -41,7 +33,7 @@
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Client implements Dispatchable
class Client implements Stdlib\DispatchableInterface
{
/**
* @const string Supported HTTP Authentication methods
Expand Down Expand Up @@ -126,7 +118,7 @@ class Client implements Dispatchable
'useragent' => 'Zend\Http\Client',
'timeout' => 10,
'adapter' => 'Zend\Http\Client\Adapter\Socket',
'httpversion' => HttpRequest::VERSION_11,
'httpversion' => Request::VERSION_11,
'storeresponse' => true,
'keepalive' => false,
'outputstream' => false,
Expand Down Expand Up @@ -249,7 +241,7 @@ public function setRequest(Request $request)
public function getRequest()
{
if (empty($this->request)) {
$this->request = new HttpRequest();
$this->request = new Request();
}
return $this->request;
}
Expand All @@ -274,7 +266,7 @@ public function setResponse(Response $response)
public function getResponse()
{
if (empty($this->response)) {
$this->response = new HttpResponse();
$this->response = new Response();
}
return $this->response;
}
Expand Down Expand Up @@ -354,8 +346,8 @@ public function setMethod($method)
{
$method = $this->getRequest()->setMethod($method)->getMethod();

if (($method == HttpRequest::METHOD_POST || $method == HttpRequest::METHOD_PUT ||
$method == HttpRequest::METHOD_DELETE || $method == HttpRequest::METHOD_PATCH)
if (($method == Request::METHOD_POST || $method == Request::METHOD_PUT ||
$method == Request::METHOD_DELETE || $method == Request::METHOD_PATCH)
&& empty($this->encType)) {
$this->setEncType(self::ENC_URLENCODED);
}
Expand Down Expand Up @@ -395,7 +387,7 @@ public function setEncType($encType, $boundary = null)
/**
* Get the encoding type
*
* @return type
* @return string
*/
public function getEncType()
{
Expand Down Expand Up @@ -451,12 +443,12 @@ public function getCookies()
/**
* Get the cookie Id (name+domain+path)
*
* @param SetCookie|Cookie $cookie
* @param Header\SetCookie|Header\Cookie $cookie
* @return string|boolean
*/
protected function getCookieId($cookie)
{
if (($cookie instanceof SetCookie) || ($cookie instanceof Cookie)) {
if (($cookie instanceof Header\SetCookie) || ($cookie instanceof Header\Cookie)) {
return $cookie->getName() . $cookie->getDomain() . $cookie->getPath();
}
return false;
Expand All @@ -465,7 +457,7 @@ protected function getCookieId($cookie)
/**
* Add a cookie
*
* @param array|ArrayIterator|SetCookie|string $cookie
* @param array|ArrayIterator|Header\SetCookie|string $cookie
* @param string $value
* @param string $version
* @param string $maxAge
Expand All @@ -480,16 +472,16 @@ public function addCookie($cookie, $value = null, $version = null, $maxAge = nul
{
if (is_array($cookie) || $cookie instanceof ArrayIterator) {
foreach ($cookie as $setCookie) {
if ($setCookie instanceof SetCookie) {
if ($setCookie instanceof Header\SetCookie) {
$this->cookies[$this->getCookieId($setCookie)] = $setCookie;
} else {
throw new Exception\InvalidArgumentException('The cookie parameter is not a valid Set-Cookie type');
}
}
} elseif ($cookie instanceof SetCookie) {
} elseif ($cookie instanceof Header\SetCookie) {
$this->cookies[$this->getCookieId($cookie)] = $cookie;
} elseif (is_string($cookie) && $value !== null) {
$setCookie = new SetCookie($cookie, $value, $version, $maxAge, $domain, $expire, $path, $secure, $httponly);
$setCookie = new Header\SetCookie($cookie, $value, $version, $maxAge, $domain, $expire, $path, $secure, $httponly);
$this->cookies[$this->getCookieId($setCookie)] = $setCookie;
} else {
throw new Exception\InvalidArgumentException('Invalid parameter type passed as Cookie');
Expand Down Expand Up @@ -736,11 +728,11 @@ public function resetParameters($clearCookies = false)
/**
* Dispatch
*
* @param Request $request
* @param Response $response
* @return Response
* @param Stdlib\RequestInterface $request
* @param Stdlib\ResponseInterface $response
* @return Stdlib\ResponseInterface
*/
public function dispatch(Request $request, Response $response = null)
public function dispatch(Stdlib\RequestInterface $request, Stdlib\ResponseInterface $response = null)
{
$response = $this->send($request);
return $response;
Expand Down Expand Up @@ -850,14 +842,14 @@ public function send(Request $request = null)
}
// cleanup the adapter
$this->adapter->setOutputStream(null);
$response = HttpResponseStream::fromStream($response, $stream);
$response = Response\Stream::fromStream($response, $stream);
$response->setStreamName($this->streamName);
if (!is_string($this->config['outputstream'])) {
// we used temp name, will need to clean up
$response->setCleanup(true);
}
} else {
$response = HttpResponse::fromString($response);
$response = Response::fromString($response);
}

// Get the cookies from response (if any)
Expand All @@ -880,7 +872,7 @@ public function send(Request $request = null)
$response->getStatusCode() == 301))) {

$this->resetParameters();
$this->setMethod(HttpRequest::METHOD_GET);
$this->setMethod(Request::METHOD_GET);
}

// If we got a well formed absolute URI
Expand Down Expand Up @@ -984,7 +976,7 @@ public function removeFileUpload($filename)
* @param string $uri
* @param string $domain
* @param boolean $secure
* @return Cookie|boolean
* @return Header\Cookie|boolean
*/
protected function prepareCookies($domain, $path, $secure)
{
Expand All @@ -1004,7 +996,7 @@ protected function prepareCookies($domain, $path, $secure)
}
}

$cookies = Cookie::fromSetCookieArray($validCookies);
$cookies = Header\Cookie::fromSetCookieArray($validCookies);
$cookies->setEncodeValue($this->config['encodecookies']);

return $cookies;
Expand All @@ -1020,7 +1012,7 @@ protected function prepareHeaders($body, $uri)
$headers = array();

// Set the host header
if ($this->config['httpversion'] == HttpRequest::VERSION_11) {
if ($this->config['httpversion'] == Request::VERSION_11) {
$host = $uri->getHost();
// If the port is not default, add it
if (!(($uri->getScheme() == 'http' && $uri->getPort() == 80) ||
Expand Down

0 comments on commit 4119467

Please sign in to comment.