Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'Maks3w-hotfix/http-header-format'
Browse files Browse the repository at this point in the history
Close #5302
Close #5253
Close #5290
  • Loading branch information
Mike Willbanks committed Oct 20, 2013
2 parents 335a3c8 + ae6c085 commit 9aa8eb3
Show file tree
Hide file tree
Showing 48 changed files with 129 additions and 46 deletions.
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/AbstractDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function fromString($headerLine)
{
$dateHeader = new static();

list($name, $date) = explode(': ', $headerLine, 2);
list($name, $date) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== strtolower($dateHeader->getFieldName())) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/AbstractLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function fromString($headerLine)
$locationHeader = new static();

// ZF-5520 - IIS bug, no space after colon
list($name, $uri) = explode(':', $headerLine, 2);
list($name, $uri) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== strtolower($locationHeader->getFieldName())) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/AcceptRanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'accept-ranges') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Age.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'age') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Allow.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'allow') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/AuthenticationInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'authentication-info') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'authorization') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'cache-control') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'connection') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentDisposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-disposition') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentEncoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-encoding') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-language') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-length') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentMD5.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-md5') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-range') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentTransferEncoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-transfer-encoding') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'content-type') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'cookie') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Expect.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'expect') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/From.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'from') {
Expand Down
21 changes: 20 additions & 1 deletion library/Zend/Http/Header/GenericHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,30 @@ class GenericHeader implements HeaderInterface
*/
public static function fromString($headerLine)
{
list($fieldName, $fieldValue) = explode(': ', $headerLine, 2);
list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);
$header = new static($fieldName, $fieldValue);
return $header;
}

/**
* Splits the header line in `name` and `value` parts.
*
* @param string $headerLine
* @return string[] `name` in the first index and `value` in the second.
* @throws Exception\InvalidArgumentException If header does not match with the format ``name:value``
*/
public static function splitHeaderLine($headerLine)
{
$parts = explode(':', $headerLine, 2);
if (count($parts) !== 2) {
throw new Exception\InvalidArgumentException('Header must match with the format "name:value"');
}

$parts[1] = ltrim($parts[1]);

return $parts;
}

/**
* Constructor
*
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/GenericMultiHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GenericMultiHeader extends GenericHeader implements MultipleHeaderInterfac
{
public static function fromString($headerLine)
{
list($fieldName, $fieldValue) = explode(': ', $headerLine, 2);
list($fieldName, $fieldValue) = GenericHeader::splitHeaderLine($headerLine);

if (strpos($fieldValue, ',')) {
$headers = array();
Expand Down
31 changes: 31 additions & 0 deletions library/Zend/Http/Header/HeaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,41 @@

namespace Zend\Http\Header;

/**
* Interface for HTTP Header classes.
*/
interface HeaderInterface
{
/**
* Factory to generate a header object from a string
*
* @param string $headerLine
* @return self
* @throws Exception\InvalidArgumentException If the header does not match RFC 2616 definition.
* @see http://tools.ietf.org/html/rfc2616#section-4.2
*/
public static function fromString($headerLine);

/**
* Retrieve header name
*
* @return string
*/
public function getFieldName();

/**
* Retrieve header value
*
* @return string
*/
public function getFieldValue();

/**
* Cast to string
*
* Returns in form of "NAME: VALUE"
*
* @return string
*/
public function toString();
}
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'host') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/IfMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'if-match') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/IfNoneMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'if-none-match') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/IfRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'if-range') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/KeepAlive.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'keep-alive') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/MaxForwards.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'max-forwards') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Pragma.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'pragma') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ProxyAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'proxy-authenticate') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/ProxyAuthorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'proxy-authorization') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'range') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Refresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'refresh') {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/RetryAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function fromString($headerLine)
{
$dateHeader = new static();

list($name, $date) = explode(': ', $headerLine, 2);
list($name, $date) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== strtolower($dateHeader->getFieldName())) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'server') {
Expand Down
3 changes: 1 addition & 2 deletions library/Zend/Http/Header/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
};
}

list($name, $value) = explode(':', $headerLine, 2);
$value = ltrim($value);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// some sites return set-cookie::value, this is to get rid of the second :
$name = (strtolower($name) =='set-cookie:') ? 'set-cookie' : $name;
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/Header/TE.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function fromString($headerLine)
{
$header = new static();

list($name, $value) = explode(': ', $headerLine, 2);
list($name, $value) = GenericHeader::splitHeaderLine($headerLine);

// check to ensure proper header type for this factory
if (strtolower($name) !== 'te') {
Expand Down
Loading

0 comments on commit 9aa8eb3

Please sign in to comment.