diff --git a/src/AbstractMessage.php b/src/AbstractMessage.php index 697e4ed03a..7faab66256 100644 --- a/src/AbstractMessage.php +++ b/src/AbstractMessage.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -15,8 +14,6 @@ /** * HTTP standard message (Request/Response) * - * @category Zend - * @package Zend_Http * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4 */ abstract class AbstractMessage extends Message diff --git a/src/Client.php b/src/Client.php index 9c064611c2..6236f24d8e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -19,9 +18,6 @@ /** * Http client - * - * @category Zend - * @package Zend\Http */ class Client implements Stdlib\DispatchableInterface { @@ -113,6 +109,7 @@ class Client implements Stdlib\DispatchableInterface 'keepalive' => false, 'outputstream' => false, 'encodecookies' => true, + 'argseparator' => null, 'rfc3986strict' => false ); @@ -355,6 +352,33 @@ public function getMethod() return $this->getRequest()->getMethod(); } + /** + * Set the query string argument separator + * + * @param string $argSeparator + * @return Client + */ + public function setArgSeparator($argSeparator) + { + $this->setOptions(array("argseparator" => $argSeparator)); + return $this; + } + + /** + * Get the query string argument separator + * + * @return string + */ + public function getArgSeparator() + { + $argSeparator = $this->config['argseparator']; + if (empty($argSeparator)) { + $argSeparator = ini_get('arg_separator.output'); + $this->setArgSeparator($argSeparator); + } + return $argSeparator; + } + /** * Set the encoding type and the boundary (if any) * @@ -469,11 +493,11 @@ public function addCookie($cookie, $value = null, $expire = null, $path = null, throw new Exception\InvalidArgumentException('The cookie parameter is not a valid Set-Cookie type'); } } - } elseif ($cookie instanceof Header\SetCookie) { - $this->cookies[$this->getCookieId($cookie)] = $cookie; } elseif (is_string($cookie) && $value !== null) { $setCookie = new Header\SetCookie($cookie, $value, $expire, $path, $domain, $secure, $httponly, $maxAge, $version); $this->cookies[$this->getCookieId($setCookie)] = $setCookie; + } elseif ($cookie instanceof Header\SetCookie) { + $this->cookies[$this->getCookieId($cookie)] = $cookie; } else { throw new Exception\InvalidArgumentException('Invalid parameter type passed as Cookie'); } @@ -777,14 +801,14 @@ public function send(Request $request = null) if (!empty($queryArray)) { $newUri = $uri->toString(); - $queryString = http_build_query($query); + $queryString = http_build_query($query, null, $this->getArgSeparator()); if ($this->config['rfc3986strict']) { $queryString = str_replace('+', '%20', $queryString); } if (strpos($newUri, '?') !== false) { - $newUri .= '&' . $queryString; + $newUri .= $this->getArgSeparator() . $queryString; } else { $newUri .= '?' . $queryString; } @@ -855,9 +879,9 @@ public function send(Request $request = null) } // Get the cookies from response (if any) - $setCookie = $response->getCookie(); - if (!empty($setCookie)) { - $this->addCookie($setCookie); + $setCookies = $response->getCookie(); + if (!empty($setCookies)) { + $this->addCookie($setCookies); } // If we got redirected, look for the Location header @@ -1294,7 +1318,6 @@ protected function doRequest(Http $uri, $method, $secure = false, $headers = arr throw new Exception\RuntimeException('Adapter does not support streaming'); } } - // HTTP connection $this->lastRawRequest = $this->adapter->write($method, $uri, $this->config['httpversion'], $headers, $body); diff --git a/src/Client/Adapter/AdapterInterface.php b/src/Client/Adapter/AdapterInterface.php index 7c8178beeb..c870aa5cb7 100644 --- a/src/Client/Adapter/AdapterInterface.php +++ b/src/Client/Adapter/AdapterInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter; @@ -15,10 +14,6 @@ * * These classes are used as connectors for Zend_Http_Client, performing the * tasks of connecting, writing, reading and closing connection to the server. - * - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter */ interface AdapterInterface { diff --git a/src/Client/Adapter/Curl.php b/src/Client/Adapter/Curl.php index 3835ebbc4b..d5becf8e08 100644 --- a/src/Client/Adapter/Curl.php +++ b/src/Client/Adapter/Curl.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter; @@ -20,10 +19,6 @@ /** * An adapter class for Zend\Http\Client based on the curl extension. * Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl - * - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter */ class Curl implements HttpAdapter, StreamInterface { @@ -374,6 +369,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo foreach ($headers as $key => $value) { $curlHeaders[] = $key . ': ' . $value; } + curl_setopt($this->curl, CURLOPT_HTTPHEADER, $curlHeaders); /** @@ -409,8 +405,8 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo } // send the request - $response = curl_exec($this->curl); + $response = curl_exec($this->curl); // if we used streaming, headers are already there if (!is_resource($this->outputStream)) { $this->response = $response; diff --git a/src/Client/Adapter/Exception/ExceptionInterface.php b/src/Client/Adapter/Exception/ExceptionInterface.php index 759b8074e0..9bb3fb3f31 100644 --- a/src/Client/Adapter/Exception/ExceptionInterface.php +++ b/src/Client/Adapter/Exception/ExceptionInterface.php @@ -5,17 +5,11 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter\Exception; use Zend\Http\Client\Exception\ExceptionInterface as HttpClientException; -/** - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter - */ interface ExceptionInterface extends HttpClientException {} diff --git a/src/Client/Adapter/Exception/InitializationException.php b/src/Client/Adapter/Exception/InitializationException.php index 0e8b264ac2..6fea4a1c43 100644 --- a/src/Client/Adapter/Exception/InitializationException.php +++ b/src/Client/Adapter/Exception/InitializationException.php @@ -5,15 +5,11 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter\Exception; /** - * - * @category Zend - * @package Zend_Application */ class InitializationException extends RuntimeException {} diff --git a/src/Client/Adapter/Exception/InvalidArgumentException.php b/src/Client/Adapter/Exception/InvalidArgumentException.php index 80fa49ded5..361790a19c 100644 --- a/src/Client/Adapter/Exception/InvalidArgumentException.php +++ b/src/Client/Adapter/Exception/InvalidArgumentException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter\Exception; @@ -13,9 +12,6 @@ use Zend\Http\Client\Exception; /** - * - * @category Zend - * @package Zend_Application */ class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface diff --git a/src/Client/Adapter/Exception/OutOfRangeException.php b/src/Client/Adapter/Exception/OutOfRangeException.php index 4b45649ea1..c126a3f25d 100644 --- a/src/Client/Adapter/Exception/OutOfRangeException.php +++ b/src/Client/Adapter/Exception/OutOfRangeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter\Exception; @@ -13,9 +12,6 @@ use Zend\Http\Client\Exception; /** - * - * @category Zend - * @package Zend_Application */ class OutOfRangeException extends Exception\OutOfRangeException implements ExceptionInterface diff --git a/src/Client/Adapter/Exception/RuntimeException.php b/src/Client/Adapter/Exception/RuntimeException.php index 26128ed31d..d26da0cd59 100644 --- a/src/Client/Adapter/Exception/RuntimeException.php +++ b/src/Client/Adapter/Exception/RuntimeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter\Exception; @@ -13,9 +12,6 @@ use Zend\Http\Client\Exception; /** - * - * @category Zend - * @package Zend_Application */ class RuntimeException extends Exception\RuntimeException implements ExceptionInterface diff --git a/src/Client/Adapter/Exception/TimeoutException.php b/src/Client/Adapter/Exception/TimeoutException.php index 75024c44f3..7928b0c789 100644 --- a/src/Client/Adapter/Exception/TimeoutException.php +++ b/src/Client/Adapter/Exception/TimeoutException.php @@ -5,15 +5,11 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter\Exception; /** - * - * @category Zend - * @package Zend_Application */ class TimeoutException extends RuntimeException implements ExceptionInterface { diff --git a/src/Client/Adapter/Proxy.php b/src/Client/Adapter/Proxy.php index 754d28ddbc..f06aa866db 100644 --- a/src/Client/Adapter/Proxy.php +++ b/src/Client/Adapter/Proxy.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter; @@ -23,10 +22,6 @@ * fall back to Zend_Http_Client_Adapter_Socket behavior. Just like the * default Socket adapter, this adapter does not require any special extensions * installed. - * - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter */ class Proxy extends Socket { diff --git a/src/Client/Adapter/Socket.php b/src/Client/Adapter/Socket.php index 694e0a0580..68604e01ec 100644 --- a/src/Client/Adapter/Socket.php +++ b/src/Client/Adapter/Socket.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter; @@ -20,10 +19,6 @@ /** * A sockets based (stream\socket\client) adapter class for Zend\Http\Client. Can be used * on almost every PHP environment, and does not require any special extensions. - * - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter */ class Socket implements HttpAdapter, StreamInterface { diff --git a/src/Client/Adapter/StreamInterface.php b/src/Client/Adapter/StreamInterface.php index 065e10441d..aaf72d92fc 100644 --- a/src/Client/Adapter/StreamInterface.php +++ b/src/Client/Adapter/StreamInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter; @@ -14,10 +13,6 @@ * An interface description for Zend_Http_Client_Adapter_Stream classes. * * This interface describes Zend_Http_Client_Adapter which supports streaming. - * - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter */ interface StreamInterface { diff --git a/src/Client/Adapter/Test.php b/src/Client/Adapter/Test.php index 92bedb980a..cde513731d 100644 --- a/src/Client/Adapter/Test.php +++ b/src/Client/Adapter/Test.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Adapter; @@ -21,10 +20,6 @@ * without actually performing an HTTP request. You should instantiate this * object manually, and then set it as the client's adapter. Then, you can * set the expected response using the setResponse() method. - * - * @category Zend - * @package Zend_Http - * @subpackage Client_Adapter */ class Test implements AdapterInterface { diff --git a/src/Client/Cookies.php b/src/Client/Cookies.php index 7432667844..c2b4ecb84e 100644 --- a/src/Client/Cookies.php +++ b/src/Client/Cookies.php @@ -5,14 +5,15 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client; use ArrayIterator; -use Zend\Http\Header\Cookie; +use Traversable; +use Zend\Http\Header\SetCookie; use Zend\Http\Response; +use Zend\Stdlib\ArrayUtils; use Zend\Uri; /** @@ -32,9 +33,6 @@ * (by passing Zend\Http\Client\Cookies::COOKIE_STRING_CONCAT). * * @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs. - * - * @category Zend - * @package Zend\Http\Client */ class Cookies { @@ -82,28 +80,21 @@ class Cookies */ protected $rawCookies = array(); - /** - * Construct - * - */ - public function __construct() - { } - /** * Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object * or as a string - in which case an object is created from the string. * - * @param Cookie|string $cookie + * @param SetCookie|string $cookie * @param Uri\Uri|string $refUri Optional reference URI (for domain, path, secure) * @throws Exception\InvalidArgumentException if invalid $cookie value */ public function addCookie($cookie, $refUri = null) { if (is_string($cookie)) { - $cookie = Cookie::fromString($cookie, $refUri); + $cookie = SetCookie::fromString($cookie, $refUri); } - if ($cookie instanceof Cookie) { + if ($cookie instanceof SetCookie) { $domain = $cookie->getDomain(); $path = $cookie->getPath(); if (!isset($this->cookies[$domain])) { @@ -128,6 +119,9 @@ public function addCookie($cookie, $refUri = null) public function addCookiesFromResponse(Response $response, $refUri) { $cookieHdrs = $response->getHeaders()->get('Set-Cookie'); + if ($cookieHdrs instanceof Traversable) { + $cookieHdrs = ArrayUtils::iteratorToArray($cookieHdrs); + } if (is_array($cookieHdrs)) { foreach ($cookieHdrs as $cookie) { @@ -262,7 +256,7 @@ protected function _flattenCookiesArray($ptr, $retAs = self::COOKIE_OBJECT) } } return $ret; - } elseif ($ptr instanceof Cookie) { + } elseif ($ptr instanceof SetCookie) { switch ($retAs) { case self::COOKIE_STRING_ARRAY: return array($ptr->__toString()); @@ -293,7 +287,7 @@ protected function _matchDomain($domain) $ret = array(); foreach (array_keys($this->cookies) as $cdom) { - if (Cookie::matchCookieDomain($cdom, $domain)) { + if (SetCookie::matchCookieDomain($cdom, $domain)) { $ret[$cdom] = $this->cookies[$cdom]; } } @@ -314,7 +308,7 @@ protected function _matchPath($domains, $path) foreach ($domains as $dom => $pathsArray) { foreach (array_keys($pathsArray) as $cpath) { - if (Cookie::matchCookiePath($cpath, $path)) { + if (SetCookie::matchCookiePath($cpath, $path)) { if (! isset($ret[$dom])) { $ret[$dom] = array(); } diff --git a/src/Client/Exception/ExceptionInterface.php b/src/Client/Exception/ExceptionInterface.php index 3f573c22d2..dbb0d985a0 100644 --- a/src/Client/Exception/ExceptionInterface.php +++ b/src/Client/Exception/ExceptionInterface.php @@ -5,17 +5,11 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Exception; use Zend\Http\Exception\ExceptionInterface as HttpException; -/** - * @category Zend - * @package Zend_Http - * @subpackage Client - */ interface ExceptionInterface extends HttpException {} diff --git a/src/Client/Exception/InvalidArgumentException.php b/src/Client/Exception/InvalidArgumentException.php index 4a899c900e..9e0221d285 100644 --- a/src/Client/Exception/InvalidArgumentException.php +++ b/src/Client/Exception/InvalidArgumentException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Exception; @@ -13,9 +12,6 @@ use Zend\Http\Exception; /** - * - * @category Zend - * @package Zend_Application */ class InvalidArgumentException extends Exception\InvalidArgumentException implements ExceptionInterface diff --git a/src/Client/Exception/OutOfRangeException.php b/src/Client/Exception/OutOfRangeException.php index 1a9b035fe0..309f575b2e 100644 --- a/src/Client/Exception/OutOfRangeException.php +++ b/src/Client/Exception/OutOfRangeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Exception; diff --git a/src/Client/Exception/RuntimeException.php b/src/Client/Exception/RuntimeException.php index f1f8e73ee3..24cff1bcfa 100644 --- a/src/Client/Exception/RuntimeException.php +++ b/src/Client/Exception/RuntimeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Client\Exception; @@ -13,9 +12,6 @@ use Zend\Http\Exception; /** - * - * @category Zend - * @package Zend_Application */ class RuntimeException extends Exception\RuntimeException implements ExceptionInterface diff --git a/src/ClientStatic.php b/src/ClientStatic.php index 758d2efa3f..dfde5e2d4a 100644 --- a/src/ClientStatic.php +++ b/src/ClientStatic.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -14,9 +13,6 @@ /** * Http static client - * - * @category Zend - * @package Zend\Http */ class ClientStatic { diff --git a/src/Cookies.php b/src/Cookies.php index 52648d36b3..f3e9aa50c0 100644 --- a/src/Cookies.php +++ b/src/Cookies.php @@ -5,15 +5,16 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; -use Zend\Http\Header\Cookie; +use ArrayIterator; +use Zend\Http\Header\SetCookie; use Zend\Http\Response; use Zend\Uri; + /** * A Zend_Http_CookieJar object is designed to contain and maintain HTTP cookies, and should * be used along with Zend_Http_Client in order to manage cookies across HTTP requests and @@ -31,12 +32,39 @@ * (by passing Zend\Http\Client\Cookies::COOKIE_STRING_CONCAT). * * @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs. - * - * @category Zend - * @package Zend\Http\Client */ class Cookies extends Headers { + /** + * Return cookie(s) as a Zend_Http_Cookie object + * + */ + const COOKIE_OBJECT = 0; + + /** + * Return cookie(s) as a string (suitable for sending in an HTTP request) + * + */ + const COOKIE_STRING_ARRAY = 1; + + /** + * Return all cookies as one long string (suitable for sending in an HTTP request) + * + */ + const COOKIE_STRING_CONCAT = 2; + + /** + * Return all cookies as one long string (strict mode) + * - Single space after the semi-colon separating each cookie + * - Remove trailing semi-colon, if any + */ + const COOKIE_STRING_CONCAT_STRICT = 3; + + /** + * @var \Zend\Http\Cookies + */ + protected $cookies = array(); + /** * @var \Zend\Http\Headers */ @@ -61,26 +89,21 @@ public static function fromString($string) ); } - public function __construct(Headers $headers) - { - $this->headers = $headers; - } - /** * Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object * or as a string - in which case an object is created from the string. * - * @param Cookie|string $cookie - * @param Uri\Uri|string $refUri Optional reference URI (for domain, path, secure) + * @param SetCookie|string $cookie + * @param Uri\Uri|string $refUri Optional reference URI (for domain, path, secure) * @throws Exception\InvalidArgumentException */ - public function addCookie(Cookie $cookie, $refUri = null) + public function addCookie($cookie, $refUri = null) { if (is_string($cookie)) { - $cookie = Cookie::fromString($cookie, $refUri); + $cookie = SetCookie::fromString($cookie, $refUri); } - if ($cookie instanceof Cookie) { + if ($cookie instanceof SetCookie) { $domain = $cookie->getDomain(); $path = $cookie->getPath(); if (!isset($this->cookies[$domain])) { @@ -106,7 +129,7 @@ public function addCookiesFromResponse(Response $response, $refUri) { $cookieHdrs = $response->getHeaders()->get('Set-Cookie'); - if (is_array($cookieHdrs)) { + if (is_array($cookieHdrs) || $cookieHdrs instanceof ArrayIterator) { foreach ($cookieHdrs as $cookie) { $this->addCookie($cookie, $refUri); } @@ -118,7 +141,7 @@ public function addCookiesFromResponse(Response $response, $refUri) /** * Get all cookies in the cookie jar as an array * - * @param int $retAs Whether to return cookies as objects of \Zend\Http\Header\Cookie or as strings + * @param int $retAs Whether to return cookies as objects of \Zend\Http\Header\SetCookie or as strings * @return array|string */ public function getAllCookies($retAs = self::COOKIE_OBJECT) @@ -175,9 +198,9 @@ public function getMatchingCookies($uri, $matchSessionCookies = true, * * @param Uri\Uri|string $uri The uri (domain and path) to match * @param string $cookieName The cookie's name - * @param int $retAs Whether to return cookies as objects of \Zend\Http\Header\Cookie or as strings + * @param int $retAs Whether to return cookies as objects of \Zend\Http\Header\SetCookie or as strings * @throws Exception\InvalidArgumentException if invalid URI specified or invalid $retAs value - * @return Cookie|string + * @return SetCookie|string */ public function getCookie($uri, $cookieName, $retAs = self::COOKIE_OBJECT) { @@ -223,7 +246,7 @@ public function getCookie($uri, $cookieName, $retAs = self::COOKIE_OBJECT) * Helper function to recursively flatten an array. Should be used when exporting the * cookies array (or parts of it) * - * @param \Zend\Http\Header\Cookie|array $ptr + * @param \Zend\Http\Header\SetCookie|array $ptr * @param int $retAs What value to return * @return array|string */ @@ -239,7 +262,7 @@ protected function _flattenCookiesArray($ptr, $retAs = self::COOKIE_OBJECT) } } return $ret; - } elseif ($ptr instanceof Cookie) { + } elseif ($ptr instanceof SetCookie) { switch ($retAs) { case self::COOKIE_STRING_ARRAY: return array($ptr->__toString()); @@ -270,7 +293,7 @@ protected function _matchDomain($domain) $ret = array(); foreach (array_keys($this->cookies) as $cdom) { - if (Cookie::matchCookieDomain($cdom, $domain)) { + if (SetCookie::matchCookieDomain($cdom, $domain)) { $ret[$cdom] = $this->cookies[$cdom]; } } @@ -291,7 +314,7 @@ protected function _matchPath($domains, $path) foreach ($domains as $dom => $pathsArray) { foreach (array_keys($pathsArray) as $cpath) { - if (Cookie::matchCookiePath($cpath, $path)) { + if (SetCookie::matchCookiePath($cpath, $path)) { if (! isset($ret[$dom])) { $ret[$dom] = array(); } diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php index d9bad0839a..e3a35bfc98 100644 --- a/src/Exception/ExceptionInterface.php +++ b/src/Exception/ExceptionInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Exception; diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 299226653e..a0f18445d6 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Exception; diff --git a/src/Exception/OutOfRangeException.php b/src/Exception/OutOfRangeException.php index b7e6bacb90..ad931ff019 100644 --- a/src/Exception/OutOfRangeException.php +++ b/src/Exception/OutOfRangeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Exception; diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 4890511d5c..2a2770206f 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Exception; diff --git a/src/Header/AbstractAccept.php b/src/Header/AbstractAccept.php index d1be22db13..bac9c7839d 100644 --- a/src/Header/AbstractAccept.php +++ b/src/Header/AbstractAccept.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -34,8 +33,6 @@ * |---| priority * * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 * @author Dolf Schimmel - Freeaqingme */ diff --git a/src/Header/AbstractDate.php b/src/Header/AbstractDate.php index 583cbea681..3b61623392 100644 --- a/src/Header/AbstractDate.php +++ b/src/Header/AbstractDate.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -26,9 +25,6 @@ * Note for 'Location' header: * While RFC 1945 requires an absolute URI, most of the browsers also support relative URI * This class allows relative URIs, and let user retrieve URI instance if strict validation needed - * - * @category Zend - * @package Zend_Http */ abstract class AbstractDate implements HeaderInterface { diff --git a/src/Header/AbstractLocation.php b/src/Header/AbstractLocation.php index 8088209c9b..8898a39ac4 100644 --- a/src/Header/AbstractLocation.php +++ b/src/Header/AbstractLocation.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -26,9 +25,6 @@ * Note for 'Location' header: * While RFC 1945 requires an absolute URI, most of the browsers also support relative URI * This class allows relative URIs, and let user retrieve URI instance if strict validation needed - * - * @category Zend - * @package Zend_Http */ abstract class AbstractLocation implements HeaderInterface { diff --git a/src/Header/Accept.php b/src/Header/Accept.php index dadd6f83a8..220a507acc 100644 --- a/src/Header/Accept.php +++ b/src/Header/Accept.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -15,8 +14,6 @@ /** * Accept Header * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ class Accept extends AbstractAccept diff --git a/src/Header/Accept/FieldValuePart/AbstractFieldValuePart.php b/src/Header/Accept/FieldValuePart/AbstractFieldValuePart.php index 09a784ca18..cb62796d9c 100644 --- a/src/Header/Accept/FieldValuePart/AbstractFieldValuePart.php +++ b/src/Header/Accept/FieldValuePart/AbstractFieldValuePart.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Accept\FieldValuePart; @@ -14,8 +13,6 @@ * Field Value Part * * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ abstract class AbstractFieldValuePart diff --git a/src/Header/Accept/FieldValuePart/AcceptFieldValuePart.php b/src/Header/Accept/FieldValuePart/AcceptFieldValuePart.php index 5ef13edab2..083b6d1f93 100644 --- a/src/Header/Accept/FieldValuePart/AcceptFieldValuePart.php +++ b/src/Header/Accept/FieldValuePart/AcceptFieldValuePart.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Accept\FieldValuePart; @@ -14,8 +13,6 @@ * Field Value Part * * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ class AcceptFieldValuePart extends AbstractFieldValuePart diff --git a/src/Header/Accept/FieldValuePart/CharsetFieldValuePart.php b/src/Header/Accept/FieldValuePart/CharsetFieldValuePart.php index b6cedf7421..d03f0cf971 100644 --- a/src/Header/Accept/FieldValuePart/CharsetFieldValuePart.php +++ b/src/Header/Accept/FieldValuePart/CharsetFieldValuePart.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Accept\FieldValuePart; @@ -14,8 +13,6 @@ * Field Value Part * * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ class CharsetFieldValuePart extends AbstractFieldValuePart diff --git a/src/Header/Accept/FieldValuePart/EncodingFieldValuePart.php b/src/Header/Accept/FieldValuePart/EncodingFieldValuePart.php index b791190a6d..9c83c39573 100644 --- a/src/Header/Accept/FieldValuePart/EncodingFieldValuePart.php +++ b/src/Header/Accept/FieldValuePart/EncodingFieldValuePart.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Accept\FieldValuePart; @@ -14,8 +13,6 @@ * Field Value Part * * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ class EncodingFieldValuePart extends AbstractFieldValuePart diff --git a/src/Header/Accept/FieldValuePart/LanguageFieldValuePart.php b/src/Header/Accept/FieldValuePart/LanguageFieldValuePart.php index f548b085d1..5ea7c5747a 100644 --- a/src/Header/Accept/FieldValuePart/LanguageFieldValuePart.php +++ b/src/Header/Accept/FieldValuePart/LanguageFieldValuePart.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Accept\FieldValuePart; @@ -14,8 +13,6 @@ * Field Value Part * * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 */ class LanguageFieldValuePart extends AbstractFieldValuePart diff --git a/src/Header/AcceptCharset.php b/src/Header/AcceptCharset.php index 8a54aae216..1b7755d197 100644 --- a/src/Header/AcceptCharset.php +++ b/src/Header/AcceptCharset.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -14,8 +13,6 @@ /** * Accept Charset Header * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2 */ class AcceptCharset extends AbstractAccept diff --git a/src/Header/AcceptEncoding.php b/src/Header/AcceptEncoding.php index 9fe38ae77f..b05733da7f 100644 --- a/src/Header/AcceptEncoding.php +++ b/src/Header/AcceptEncoding.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -14,8 +13,6 @@ /** * Accept Encoding Header * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3 */ class AcceptEncoding extends AbstractAccept diff --git a/src/Header/AcceptLanguage.php b/src/Header/AcceptLanguage.php index f734cb4e04..4b953d2b39 100644 --- a/src/Header/AcceptLanguage.php +++ b/src/Header/AcceptLanguage.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -15,8 +14,6 @@ /** * Accept Language Header * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 */ class AcceptLanguage extends AbstractAccept diff --git a/src/Header/AcceptRanges.php b/src/Header/AcceptRanges.php index edb024ac97..4edd3a54de 100644 --- a/src/Header/AcceptRanges.php +++ b/src/Header/AcceptRanges.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,8 +12,6 @@ /** * Accept Ranges Header * - * @category Zend - * @package Zend\Http\Header * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.5 */ class AcceptRanges implements HeaderInterface diff --git a/src/Header/Age.php b/src/Header/Age.php index 89d63f4e73..123ef7bd1b 100644 --- a/src/Header/Age.php +++ b/src/Header/Age.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Age HTTP Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.6 */ class Age implements HeaderInterface diff --git a/src/Header/Allow.php b/src/Header/Allow.php index 16a0914c9c..c2418a1d02 100644 --- a/src/Header/Allow.php +++ b/src/Header/Allow.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -15,9 +14,6 @@ /** * Allow Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7 */ class Allow implements HeaderInterface diff --git a/src/Header/AuthenticationInfo.php b/src/Header/AuthenticationInfo.php index 7b0808f8ad..0b6fe08459 100644 --- a/src/Header/AuthenticationInfo.php +++ b/src/Header/AuthenticationInfo.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Authorization.php b/src/Header/Authorization.php index 61e8247730..8b5f52bb2e 100644 --- a/src/Header/Authorization.php +++ b/src/Header/Authorization.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/CacheControl.php b/src/Header/CacheControl.php index 86a36b8abe..b9c61fc618 100644 --- a/src/Header/CacheControl.php +++ b/src/Header/CacheControl.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Connection.php b/src/Header/Connection.php index ba8fcaa558..d439b94c6f 100644 --- a/src/Header/Connection.php +++ b/src/Header/Connection.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Connection Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.10 */ class Connection implements HeaderInterface diff --git a/src/Header/ContentDisposition.php b/src/Header/ContentDisposition.php index 213413bc9f..62baf14521 100644 --- a/src/Header/ContentDisposition.php +++ b/src/Header/ContentDisposition.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ContentEncoding.php b/src/Header/ContentEncoding.php index fe733aefaf..dbde3539ec 100644 --- a/src/Header/ContentEncoding.php +++ b/src/Header/ContentEncoding.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ContentLanguage.php b/src/Header/ContentLanguage.php index f47129f0ad..49afd7f4bc 100644 --- a/src/Header/ContentLanguage.php +++ b/src/Header/ContentLanguage.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ContentLength.php b/src/Header/ContentLength.php index cd26df3f74..4b1a8367e8 100644 --- a/src/Header/ContentLength.php +++ b/src/Header/ContentLength.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ContentLocation.php b/src/Header/ContentLocation.php index ab146755d0..bf21fc7632 100644 --- a/src/Header/ContentLocation.php +++ b/src/Header/ContentLocation.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Content-Location Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.14 */ class ContentLocation extends AbstractLocation diff --git a/src/Header/ContentMD5.php b/src/Header/ContentMD5.php index 435839beff..cfc2c54c16 100644 --- a/src/Header/ContentMD5.php +++ b/src/Header/ContentMD5.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ContentRange.php b/src/Header/ContentRange.php index 08d4b071bc..6345ded968 100644 --- a/src/Header/ContentRange.php +++ b/src/Header/ContentRange.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ContentTransferEncoding.php b/src/Header/ContentTransferEncoding.php new file mode 100644 index 0000000000..43dfe9c998 --- /dev/null +++ b/src/Header/ContentTransferEncoding.php @@ -0,0 +1,51 @@ +value = $value; + + return $header; + } + + public function getFieldName() + { + return 'Content-Transfer-Encoding'; + } + + public function getFieldValue() + { + return $this->value; + } + + public function toString() + { + return 'Content-Transfer-Encoding: ' . $this->getFieldValue(); + } + +} diff --git a/src/Header/ContentType.php b/src/Header/ContentType.php index 4f16178492..33eb39dcb7 100644 --- a/src/Header/ContentType.php +++ b/src/Header/ContentType.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Cookie.php b/src/Header/Cookie.php index e6f8fa3854..abaea00765 100644 --- a/src/Header/Cookie.php +++ b/src/Header/Cookie.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Date.php b/src/Header/Date.php index 4733fe3d40..daaf0c6320 100644 --- a/src/Header/Date.php +++ b/src/Header/Date.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Date Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.18 */ class Date extends AbstractDate diff --git a/src/Header/Etag.php b/src/Header/Etag.php index 2e6a20c31c..2bcff641e5 100644 --- a/src/Header/Etag.php +++ b/src/Header/Etag.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Exception/ExceptionInterface.php b/src/Header/Exception/ExceptionInterface.php index 992eee03d5..dcfc83e2b9 100644 --- a/src/Header/Exception/ExceptionInterface.php +++ b/src/Header/Exception/ExceptionInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Exception; diff --git a/src/Header/Exception/InvalidArgumentException.php b/src/Header/Exception/InvalidArgumentException.php index 0a0ff67ac9..ca7e8aad7f 100644 --- a/src/Header/Exception/InvalidArgumentException.php +++ b/src/Header/Exception/InvalidArgumentException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Exception; diff --git a/src/Header/Exception/RuntimeException.php b/src/Header/Exception/RuntimeException.php index 2c77c79bd1..7e0c5b5e46 100644 --- a/src/Header/Exception/RuntimeException.php +++ b/src/Header/Exception/RuntimeException.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header\Exception; diff --git a/src/Header/Expect.php b/src/Header/Expect.php index 16312fa720..81b70e9761 100644 --- a/src/Header/Expect.php +++ b/src/Header/Expect.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Expires.php b/src/Header/Expires.php index 648a92356f..70e52a3245 100644 --- a/src/Header/Expires.php +++ b/src/Header/Expires.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Expires Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21 */ class Expires extends AbstractDate diff --git a/src/Header/From.php b/src/Header/From.php index 009be96ab7..96149bb7b3 100644 --- a/src/Header/From.php +++ b/src/Header/From.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/GenericHeader.php b/src/Header/GenericHeader.php index e2855be64c..848f84a812 100644 --- a/src/Header/GenericHeader.php +++ b/src/Header/GenericHeader.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Content-Location Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers */ class GenericHeader implements HeaderInterface { diff --git a/src/Header/GenericMultiHeader.php b/src/Header/GenericMultiHeader.php index 94bc75cbfe..91b0b67cc3 100644 --- a/src/Header/GenericMultiHeader.php +++ b/src/Header/GenericMultiHeader.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/HeaderInterface.php b/src/Header/HeaderInterface.php index 07c7c5ba44..cde5cb1b02 100644 --- a/src/Header/HeaderInterface.php +++ b/src/Header/HeaderInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Host.php b/src/Header/Host.php index e430f34514..9c8cfa1d73 100644 --- a/src/Header/Host.php +++ b/src/Header/Host.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/IfMatch.php b/src/Header/IfMatch.php index 5588642e19..9b03c0c0a9 100644 --- a/src/Header/IfMatch.php +++ b/src/Header/IfMatch.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/IfModifiedSince.php b/src/Header/IfModifiedSince.php index d8d36600d0..23690ae5cb 100644 --- a/src/Header/IfModifiedSince.php +++ b/src/Header/IfModifiedSince.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * If-Modified-Since Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.25 */ class IfModifiedSince extends AbstractDate diff --git a/src/Header/IfNoneMatch.php b/src/Header/IfNoneMatch.php index 98a2a148f5..a0d4080b1b 100644 --- a/src/Header/IfNoneMatch.php +++ b/src/Header/IfNoneMatch.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/IfRange.php b/src/Header/IfRange.php index 398f2301d3..c5bd2bd9b8 100644 --- a/src/Header/IfRange.php +++ b/src/Header/IfRange.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/IfUnmodifiedSince.php b/src/Header/IfUnmodifiedSince.php index 4365b0a528..237cb9fa71 100644 --- a/src/Header/IfUnmodifiedSince.php +++ b/src/Header/IfUnmodifiedSince.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * If-Unmodified-Since Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.28 */ class IfUnmodifiedSince extends AbstractDate diff --git a/src/Header/KeepAlive.php b/src/Header/KeepAlive.php index d34d72ef0c..e7fcf8f23a 100644 --- a/src/Header/KeepAlive.php +++ b/src/Header/KeepAlive.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/LastModified.php b/src/Header/LastModified.php index 0d0fb71dd1..797164e6bd 100644 --- a/src/Header/LastModified.php +++ b/src/Header/LastModified.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Last-Modified Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29 */ class LastModified extends AbstractDate diff --git a/src/Header/Location.php b/src/Header/Location.php index 2018f90660..299b67b1ee 100644 --- a/src/Header/Location.php +++ b/src/Header/Location.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -14,9 +13,6 @@ /** * Location Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 */ class Location extends AbstractLocation diff --git a/src/Header/MaxForwards.php b/src/Header/MaxForwards.php index ff27600283..c4a8f44380 100644 --- a/src/Header/MaxForwards.php +++ b/src/Header/MaxForwards.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/MultipleHeaderInterface.php b/src/Header/MultipleHeaderInterface.php index f0987fb2e0..3a14c90839 100644 --- a/src/Header/MultipleHeaderInterface.php +++ b/src/Header/MultipleHeaderInterface.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Pragma.php b/src/Header/Pragma.php index bfe7b54baf..4220631229 100644 --- a/src/Header/Pragma.php +++ b/src/Header/Pragma.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ProxyAuthenticate.php b/src/Header/ProxyAuthenticate.php index db508faf3a..6399e8436e 100644 --- a/src/Header/ProxyAuthenticate.php +++ b/src/Header/ProxyAuthenticate.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/ProxyAuthorization.php b/src/Header/ProxyAuthorization.php index 872b2537f6..129a2ee397 100644 --- a/src/Header/ProxyAuthorization.php +++ b/src/Header/ProxyAuthorization.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Range.php b/src/Header/Range.php index 27429d433a..eb6cddeaa4 100644 --- a/src/Header/Range.php +++ b/src/Header/Range.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Referer.php b/src/Header/Referer.php index 5b44c68a64..586074e898 100644 --- a/src/Header/Referer.php +++ b/src/Header/Referer.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -15,9 +14,6 @@ /** * Content-Location Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.36 */ class Referer extends AbstractLocation diff --git a/src/Header/Refresh.php b/src/Header/Refresh.php index 7ebde812f4..0edd656150 100644 --- a/src/Header/Refresh.php +++ b/src/Header/Refresh.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/RetryAfter.php b/src/Header/RetryAfter.php index 7d26fffee6..4c1ec92d90 100644 --- a/src/Header/RetryAfter.php +++ b/src/Header/RetryAfter.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; @@ -13,9 +12,6 @@ /** * Retry-After HTTP Header * - * @category Zend - * @package Zend_Http - * @subpackage Headers * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.37 */ class RetryAfter extends AbstractDate diff --git a/src/Header/Server.php b/src/Header/Server.php index 8e26e1e798..514810f49f 100644 --- a/src/Header/Server.php +++ b/src/Header/Server.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/SetCookie.php b/src/Header/SetCookie.php index 0abce62517..fde66b9b55 100644 --- a/src/Header/SetCookie.php +++ b/src/Header/SetCookie.php @@ -5,12 +5,12 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; use Closure; +use Zend\Uri\UriFactory; /** * @throws Exception\InvalidArgumentException @@ -98,6 +98,7 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false) $setCookieProcessor = function ($headerLine) use ($setCookieClass) { $header = new $setCookieClass; $keyValuePairs = preg_split('#;\s*#', $headerLine); + foreach ($keyValuePairs as $keyValue) { if (strpos($keyValue, '=')) { list($headerKey, $headerValue) = preg_split('#=\s*#', $keyValue, 2); @@ -506,6 +507,93 @@ public function isValidForRequest($requestDomain, $path, $isSecure = false) } + /** + * Checks whether the cookie should be sent or not in a specific scenario + * + * @param string|Zend\Uri\Uri $uri URI to check against (secure, domain, path) + * @param boolean $matchSessionCookies Whether to send session cookies + * @param int $now Override the current time when checking for expiry time + * @return boolean + */ + public function match($uri, $matchSessionCookies = true, $now = null) + { + if (is_string ($uri)) { + $uri = UriFactory::factory($uri); + } + + // Make sure we have a valid Zend_Uri_Http object + if (! ($uri->isValid() && ($uri->getScheme() == 'http' || $uri->getScheme() =='https'))) { + throw new Exception\InvalidArgumentException('Passed URI is not a valid HTTP or HTTPS URI'); + } + + // Check that the cookie is secure (if required) and not expired + if ($this->secure && $uri->getScheme() != 'https') return false; + if ($this->isExpired($now)) return false; + if ($this->isSessionCookie() && ! $matchSessionCookies) return false; + + // Check if the domain matches + if (! self::matchCookieDomain($this->getDomain(), $uri->getHost())) { + return false; + } + + // Check that path matches using prefix match + if (! self::matchCookiePath($this->getPath(), $uri->getPath())) { + return false; + } + + // If we didn't die until now, return true. + return true; + } + + /** + * Check if a cookie's domain matches a host name. + * + * Used by Zend\Http\Cookies for cookie matching + * + * @param string $cookieDomain + * @param string $host + * + * @return boolean + */ + public static function matchCookieDomain($cookieDomain, $host) + { + if (! $cookieDomain) { + throw new Exception\InvalidArgumentException('$cookieDomain is expected to be a cookie domain'); + } + + if (! $host) { + throw new Exception\InvalidArgumentException('$host is expected to be a host name'); + } + + $cookieDomain = strtolower($cookieDomain); + $host = strtolower($host); + // Check for either exact match or suffix match + return ($cookieDomain == $host || + preg_match('/' . preg_quote($cookieDomain) . '$/', $host)); + } + + /** + * Check if a cookie's path matches a URL path + * + * Used by Zend\Http\Cookies for cookie matching + * + * @param string $cookiePath + * @param string $path + * @return boolean + */ + public static function matchCookiePath($cookiePath, $path) + { + if (! $cookiePath) { + throw new Exception\InvalidArgumentException('$cookiePath is expected to be a cookie path'); + } + + if (! $path) { + throw new Exception\InvalidArgumentException('$path is expected to be a host name'); + } + + return (strpos($path, $cookiePath) === 0); + } + public function toString() { return 'Set-Cookie: ' . $this->getFieldValue(); diff --git a/src/Header/TE.php b/src/Header/TE.php index d873b25520..98b424bc9d 100644 --- a/src/Header/TE.php +++ b/src/Header/TE.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Trailer.php b/src/Header/Trailer.php index 2a1ae021eb..a4947e72d7 100644 --- a/src/Header/Trailer.php +++ b/src/Header/Trailer.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/TransferEncoding.php b/src/Header/TransferEncoding.php index 090d49d3c4..1f6e062d3d 100644 --- a/src/Header/TransferEncoding.php +++ b/src/Header/TransferEncoding.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Upgrade.php b/src/Header/Upgrade.php index 26add6c49f..04cf8969d0 100644 --- a/src/Header/Upgrade.php +++ b/src/Header/Upgrade.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/UserAgent.php b/src/Header/UserAgent.php index fb8cf7423a..cd0135f132 100644 --- a/src/Header/UserAgent.php +++ b/src/Header/UserAgent.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Vary.php b/src/Header/Vary.php index 6f7d4156a9..12cec83e98 100644 --- a/src/Header/Vary.php +++ b/src/Header/Vary.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Via.php b/src/Header/Via.php index 06077a5ad8..1d2b14c83f 100644 --- a/src/Header/Via.php +++ b/src/Header/Via.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/WWWAuthenticate.php b/src/Header/WWWAuthenticate.php index 4c2c3355bc..bf3f99edee 100644 --- a/src/Header/WWWAuthenticate.php +++ b/src/Header/WWWAuthenticate.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/Header/Warning.php b/src/Header/Warning.php index 920c712684..5b28460338 100644 --- a/src/Header/Warning.php +++ b/src/Header/Warning.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Header; diff --git a/src/HeaderLoader.php b/src/HeaderLoader.php index d3b8adebab..036fdbb15f 100644 --- a/src/HeaderLoader.php +++ b/src/HeaderLoader.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -14,9 +13,6 @@ /** * Plugin Class Loader implementation for HTTP headers - * - * @category Zend - * @package Zend_Http */ class HeaderLoader extends PluginClassLoader { @@ -42,6 +38,7 @@ class HeaderLoader extends PluginClassLoader 'contentlocation' => 'Zend\Http\Header\ContentLocation', 'contentmd5' => 'Zend\Http\Header\ContentMD5', 'contentrange' => 'Zend\Http\Header\ContentRange', + 'contenttransferencoding' => 'Zend\Http\Header\ContentTransferEncoding', 'contenttype' => 'Zend\Http\Header\ContentType', 'cookie' => 'Zend\Http\Header\Cookie', 'date' => 'Zend\Http\Header\Date', diff --git a/src/Headers.php b/src/Headers.php index 0bf7609211..6263ac5712 100644 --- a/src/Headers.php +++ b/src/Headers.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -21,8 +20,6 @@ * Basic HTTP headers collection functionality * Handles aggregation of headers * - * @category Zend - * @package Zend_Http * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 */ class Headers implements Countable, Iterator diff --git a/src/PhpEnvironment/RemoteAddress.php b/src/PhpEnvironment/RemoteAddress.php index 4fdaf93b60..b714d46df4 100644 --- a/src/PhpEnvironment/RemoteAddress.php +++ b/src/PhpEnvironment/RemoteAddress.php @@ -5,16 +5,12 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\PhpEnvironment; /** * Functionality for determining client IP address. - * - * @category Zend - * @package Zend_Http */ class RemoteAddress { diff --git a/src/PhpEnvironment/Request.php b/src/PhpEnvironment/Request.php index eaa33809b3..38ee9a63c3 100644 --- a/src/PhpEnvironment/Request.php +++ b/src/PhpEnvironment/Request.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\PhpEnvironment; @@ -18,9 +17,6 @@ /** * HTTP Request for current PHP environment - * - * @category Zend - * @package Zend_Http */ class Request extends HttpRequest { diff --git a/src/PhpEnvironment/Response.php b/src/PhpEnvironment/Response.php index 458c075c79..f0400927a6 100644 --- a/src/PhpEnvironment/Response.php +++ b/src/PhpEnvironment/Response.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\PhpEnvironment; @@ -15,9 +14,6 @@ /** * HTTP Response for current PHP environment - * - * @category Zend - * @package Zend_Http */ class Response extends HttpResponse { @@ -29,11 +25,6 @@ class Response extends HttpResponse */ protected $version; - /** - * @var bool - */ - protected $headersSent = false; - /** * @var bool */ @@ -73,7 +64,7 @@ protected function detectVersion() */ public function headersSent() { - return $this->headersSent; + return headers_sent(); } /** diff --git a/src/Request.php b/src/Request.php index b5be181b47..df568f104e 100644 --- a/src/Request.php +++ b/src/Request.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -19,8 +18,6 @@ /** * HTTP Request * - * @category Zend - * @package Zend_Http * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5 */ class Request extends AbstractMessage implements RequestInterface @@ -37,6 +34,7 @@ class Request extends AbstractMessage implements RequestInterface const METHOD_TRACE = 'TRACE'; const METHOD_CONNECT = 'CONNECT'; const METHOD_PATCH = 'PATCH'; + const METHOD_PROPFIND= 'PROPFIND'; /**#@-*/ /** @@ -370,6 +368,16 @@ public function isOptions() return ($this->method === self::METHOD_OPTIONS); } + /** + * Is this a PROPFIND method request? + * + * @return bool + */ + public function isPropFind() + { + return ($this->method === self::METHOD_PROPFIND); + } + /** * Is this a GET method request? * diff --git a/src/Response.php b/src/Response.php index 6a703ecdfa..59716b435e 100644 --- a/src/Response.php +++ b/src/Response.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http; @@ -16,8 +15,6 @@ /** * HTTP Response * - * @category Zend - * @package Zend_Http * @link http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6 */ class Response extends AbstractMessage implements ResponseInterface diff --git a/src/Response/Stream.php b/src/Response/Stream.php index 88348e5543..990cadb22e 100644 --- a/src/Response/Stream.php +++ b/src/Response/Stream.php @@ -5,7 +5,6 @@ * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @package Zend_Http */ namespace Zend\Http\Response; @@ -16,9 +15,6 @@ /** * Represents an HTTP response message as PHP stream resource - * - * @package Zend_Http - * @subpackage Response */ class Stream extends Response { @@ -59,6 +55,26 @@ class Stream extends Response */ protected $cleanup; + /** + * Set content length + * + * @param int $contentLength + */ + public function setContentLength($contentLength = null) + { + $this->contentLength = $contentLength; + } + + /** + * Get content length + * + * @return int|null + */ + public function getContentLength() + { + return $this->contentLength; + } + /** * Get the response as stream * @@ -182,12 +198,13 @@ public static function fromStream($responseString, $stream) $headers = $response->getHeaders(); foreach ($headers as $header) { if ($header instanceof \Zend\Http\Header\ContentLength) { - $response->contentLength = (int) $header->getFieldValue(); - if (strlen($response->content) > $response->contentLength) { + $response->setContentLength((int) $header->getFieldValue()); + $contentLength = $response->getContentLength(); + if (strlen($response->content) > $contentLength) { throw new Exception\OutOfRangeException(sprintf( 'Too much content was extracted from the stream (%d instead of %d bytes)', strlen($response->content), - $response->contentLength + $contentLength )); } break; @@ -242,10 +259,11 @@ public function getRawBody() */ protected function readStream() { - if (null !== $this->contentLength) { - $bytes = $this->contentLength - $this->contentStreamed; + $contentLength = $this->getContentLength(); + if (null !== $contentLength) { + $bytes = $contentLength - $this->contentStreamed; } else { - $bytes = -1; //Read the whole buffer + $bytes = -1; // Read the whole buffer } if (!is_resource($this->stream) || $bytes == 0) { @@ -255,7 +273,7 @@ protected function readStream() $this->content .= stream_get_contents($this->stream, $bytes); $this->contentStreamed += strlen($this->content); - if ($this->contentLength == $this->contentStreamed) { + if ($this->getContentLength() == $this->contentStreamed) { $this->stream = null; } } diff --git a/test/Client/CommonHttpTests.php b/test/Client/CommonHttpTests.php index 54c6cd205f..511e9b5c00 100644 --- a/test/Client/CommonHttpTests.php +++ b/test/Client/CommonHttpTests.php @@ -113,20 +113,28 @@ protected function tearDown() * Simple request tests */ + public function methodProvider() + { + return array( + array(Request::METHOD_GET), + array(Request::METHOD_POST), + array(Request::METHOD_OPTIONS), + array(Request::METHOD_PUT), + array(Request::METHOD_DELETE), + array(Request::METHOD_PATCH), + ); + } + /** * Test simple requests * + * @dataProvider methodProvider */ - public function testSimpleRequests() + public function testSimpleRequests($method) { - $methods= array(Request::METHOD_GET, Request::METHOD_POST, Request::METHOD_OPTIONS, - Request::METHOD_PUT, Request::METHOD_DELETE, Request::METHOD_PATCH); - - foreach ($methods as $method) { - $this->client->setMethod($method); - $res = $this->client->send(); - $this->assertTrue($res->isSuccess(), "HTTP {$method} request failed."); - } + $this->client->setMethod($method); + $res = $this->client->send(); + $this->assertTrue($res->isSuccess(), "HTTP {$method} request failed."); } /** @@ -977,6 +985,21 @@ public function testContentTypeAdditionlInfo($params) $request->getHeaders()->get('Content-Type')->getFieldValue()); } + /** + * @group 2774 + * @group 2745 + */ + public function testUsesProvidedArgSeparator() + { + $this->client->setArgSeparator(';'); + $request = new Request(); + $request->setUri('http://framework.zend.com'); + $request->setQuery(array('foo' => 'bar', 'baz' => 'bat')); + $this->client->send($request); + $rawRequest = $this->client->getLastRawRequest(); + $this->assertContains('?foo=bar;baz=bat', $rawRequest); + } + /** * Internal helpder function to get the contents of test files * @@ -1045,5 +1068,4 @@ public static function invalidConfigProvider() array(55) ); } - } diff --git a/test/ClientTest.php b/test/ClientTest.php index b73af73c41..cd983343dd 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -12,15 +12,42 @@ use ReflectionClass; use Zend\Http\Client; +use Zend\Http\Cookies; +use Zend\Http\Exception; use Zend\Http\Header\AcceptEncoding; use Zend\Http\Header\SetCookie; -use Zend\Http\Response; use Zend\Http\Request; -use Zend\Http\Exception; +use Zend\Http\Response; class ClientTest extends \PHPUnit_Framework_TestCase { + public function testIfCookiesAreSticky() + { + $initialCookies = array( + new SetCookie('foo', 'far', null, '/', 'www.domain.com' ), + new SetCookie('bar', 'biz', null, '/', 'www.domain.com') + ); + + $requestString = "GET http://www.domain.com/index.php HTTP/1.1\r\nHost: domain.com\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20100101 Firefox/16.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive\r\n"; + $request = Request::fromString($requestString); + + $client = new Client('http://www.domain.com/'); + $client->setRequest($request); + $client->addCookie($initialCookies); + + $cookies = new Cookies($client->getRequest()->getHeaders()); + $rawHeaders = "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Encoding: gzip\r\nContent-Type: application/javascript\r\nDate: Sun, 18 Nov 2012 16:16:08 GMT\r\nServer: nginx/1.1.19\r\nSet-Cookie: baz=bah; domain=www.domain.com; path=/\r\nSet-Cookie: joe=test; domain=www.domain.com; path=/\r\nVary: Accept-Encoding\r\nX-Powered-By: PHP/5.3.10-1ubuntu3.4\r\nConnection: keep-alive\r\n"; + $response = Response::fromString($rawHeaders); + $client->setResponse($response); + + $cookies->addCookiesFromResponse($client->getResponse(), $client->getUri()); + + $client->addCookie( $cookies->getMatchingCookies($client->getUri()) ); + + $this->assertEquals(4, count($client->getCookies())); + } + public function testClientRetrievesUppercaseHttpMethodFromRequestObject() { $client = new Client; @@ -69,14 +96,13 @@ public function testIfNullValueCookiesThrowsException() public function testIfCookieHeaderCanBeSet() { - $header = new SetCookie('foo'); - + $header = array(new SetCookie('foo', 'bar')); $client = new Client(); $client->addCookie($header); $cookies = $client->getCookies(); $this->assertEquals(1, count($cookies)); - $this->assertEquals($header, $cookies['foo']); + $this->assertEquals($header[0], $cookies['foo']); } public function testIfArrayOfHeadersCanBeSet() @@ -107,6 +133,28 @@ public function testIfArrayIteratorOfHeadersCanBeSet() $this->assertEquals(2, count($cookies)); } + /** + * @group 2774 + * @group 2745 + */ + public function testArgSeparatorDefaultsToIniSetting() + { + $argSeparator = ini_get('arg_separator.output'); + $client = new Client(); + $this->assertEquals($argSeparator, $client->getArgSeparator()); + } + + /** + * @group 2774 + * @group 2745 + */ + public function testCanOverrideArgSeparator() + { + $client = new Client(); + $client->setArgSeparator(';'); + $this->assertEquals(';', $client->getArgSeparator()); + } + public function testClientUsesAcceptEncodingHeaderFromRequestObject() { $client = new Client(); diff --git a/test/CookiesTest.php b/test/CookiesTest.php new file mode 100644 index 0000000000..bc148fa7d2 --- /dev/null +++ b/test/CookiesTest.php @@ -0,0 +1,47 @@ +setDomain("www.zend.com"); + $header->setPath("/"); + $headers->addHeader($header); + $response->setHeaders($headers); + + $response = \Zend\Http\Cookies::fromResponse($response, "http://www.zend.com"); + $this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo')); + } + + public function testFromResponseInCookie() + { + $response = new Response(); + $headers = new Headers(); + $header = new \Zend\Http\Header\SetCookie("foo", "bar"); + $header->setDomain("www.zend.com"); + $header->setPath("/"); + $headers->addHeader($header); + $response->setHeaders($headers); + + $response = \Zend\Http\Client\Cookies::fromResponse($response, "http://www.zend.com"); + $this->assertSame($header, $response->getCookie('http://www.zend.com', 'foo')); + } +} diff --git a/test/Header/ContentTransferEncodingTest.php b/test/Header/ContentTransferEncodingTest.php new file mode 100644 index 0000000000..36cf185a15 --- /dev/null +++ b/test/Header/ContentTransferEncodingTest.php @@ -0,0 +1,51 @@ +assertInstanceOf('Zend\Http\Header\HeaderInterface', $contentTransferEncodingHeader); + $this->assertInstanceOf('Zend\Http\Header\ContentTransferEncoding', $contentTransferEncodingHeader); + } + + public function testContentTransferEncodingGetFieldNameReturnsHeaderName() + { + $contentTransferEncodingHeader = new ContentTransferEncoding(); + $this->assertEquals('Content-Transfer-Encoding', $contentTransferEncodingHeader->getFieldName()); + } + + public function testContentTransferEncodingGetFieldValueReturnsProperValue() + { + $this->markTestIncomplete('ContentTransferEncoding needs to be completed'); + + $contentTransferEncodingHeader = new ContentTransferEncoding(); + $this->assertEquals('xxx', $contentTransferEncodingHeader->getFieldValue()); + } + + public function testContentTransferEncodingToStringReturnsHeaderFormattedString() + { + $this->markTestIncomplete('ContentTransferEncoding needs to be completed'); + + $contentTransferEncodingHeader = new ContentTransferEncoding(); + + // @todo set some values, then test output + $this->assertEmpty('Content-Transfer-Encoding: xxx', $contentTransferEncodingHeader->toString()); + } + + /** Implmentation specific tests here */ + +}