Upgrade to latest Symfony HttpFoundation tag. Closes #1865.
This commit is contained in:
@@ -131,6 +131,8 @@ class Response
|
||||
* @param integer $status The response status code
|
||||
* @param array $headers An array of response headers
|
||||
*
|
||||
* @throws \InvalidArgumentException When the HTTP status code is not valid
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($content = '', $status = 200, $headers = array())
|
||||
@@ -231,7 +233,7 @@ class Response
|
||||
$headers->remove('Content-Length');
|
||||
}
|
||||
|
||||
if ('HEAD' === $request->getMethod()) {
|
||||
if ($request->isMethod('HEAD')) {
|
||||
// cf. RFC2616 14.13
|
||||
$length = $headers->get('Content-Length');
|
||||
$this->setContent(null);
|
||||
@@ -251,6 +253,16 @@ class Response
|
||||
$this->headers->set('expires', -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we need to remove Cache-Control for ssl encrypted downloads when using IE < 9
|
||||
* @link http://support.microsoft.com/kb/323308
|
||||
*/
|
||||
if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
|
||||
if (intval(preg_replace("/(MSIE )(.*?);/", "$2", $match[0])) < 9) {
|
||||
$this->headers->remove('Cache-Control');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -270,7 +282,7 @@ class Response
|
||||
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
|
||||
|
||||
// headers
|
||||
foreach ($this->headers->all() as $name => $values) {
|
||||
foreach ($this->headers->allPreserveCase() as $name => $values) {
|
||||
foreach ($values as $value) {
|
||||
header($name.': '.$value, false);
|
||||
}
|
||||
@@ -336,6 +348,8 @@ class Response
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setContent($content)
|
||||
@@ -431,7 +445,7 @@ class Response
|
||||
/**
|
||||
* Retrieves the status code for the current web response.
|
||||
*
|
||||
* @return string Status code
|
||||
* @return integer Status code
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -499,7 +513,7 @@ class Response
|
||||
*
|
||||
* Fresh responses may be served from cache without any interaction with the
|
||||
* origin. A response is considered fresh when it includes a Cache-Control/max-age
|
||||
* indicator or Expiration header and the calculated age is less than the freshness lifetime.
|
||||
* indicator or Expires header and the calculated age is less than the freshness lifetime.
|
||||
*
|
||||
* @return Boolean true if the response is fresh, false otherwise
|
||||
*
|
||||
@@ -612,8 +626,8 @@ class Response
|
||||
*/
|
||||
public function getAge()
|
||||
{
|
||||
if ($age = $this->headers->get('Age')) {
|
||||
return $age;
|
||||
if (null !== $age = $this->headers->get('Age')) {
|
||||
return (int) $age;
|
||||
}
|
||||
|
||||
return max(time() - $this->getDate()->format('U'), 0);
|
||||
@@ -638,21 +652,26 @@ class Response
|
||||
/**
|
||||
* Returns the value of the Expires header as a DateTime instance.
|
||||
*
|
||||
* @return \DateTime A DateTime instance
|
||||
* @return \DateTime|null A DateTime instance or null if the header does not exist
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getExpires()
|
||||
{
|
||||
return $this->headers->getDate('Expires');
|
||||
try {
|
||||
return $this->headers->getDate('Expires');
|
||||
} catch (\RuntimeException $e) {
|
||||
// according to RFC 2616 invalid date formats (e.g. "0" and "-1") must be treated as in the past
|
||||
return \DateTime::createFromFormat(DATE_RFC2822, 'Sat, 01 Jan 00 00:00:00 +0000');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Expires HTTP header with a DateTime instance.
|
||||
*
|
||||
* If passed a null value, it removes the header.
|
||||
* Passing null as value will remove the header.
|
||||
*
|
||||
* @param \DateTime $date A \DateTime instance
|
||||
* @param \DateTime|null $date A \DateTime instance or null to remove the header
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
@@ -672,7 +691,7 @@ class Response
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of seconds after the time specified in the response's Date
|
||||
* Returns the number of seconds after the time specified in the response's Date
|
||||
* header when the the response should no longer be considered fresh.
|
||||
*
|
||||
* First, it checks for a s-maxage directive, then a max-age directive, and then it falls
|
||||
@@ -684,12 +703,12 @@ class Response
|
||||
*/
|
||||
public function getMaxAge()
|
||||
{
|
||||
if ($age = $this->headers->getCacheControlDirective('s-maxage')) {
|
||||
return $age;
|
||||
if ($this->headers->hasCacheControlDirective('s-maxage')) {
|
||||
return (int) $this->headers->getCacheControlDirective('s-maxage');
|
||||
}
|
||||
|
||||
if ($age = $this->headers->getCacheControlDirective('max-age')) {
|
||||
return $age;
|
||||
if ($this->headers->hasCacheControlDirective('max-age')) {
|
||||
return (int) $this->headers->getCacheControlDirective('max-age');
|
||||
}
|
||||
|
||||
if (null !== $this->getExpires()) {
|
||||
@@ -750,7 +769,7 @@ class Response
|
||||
*/
|
||||
public function getTtl()
|
||||
{
|
||||
if ($maxAge = $this->getMaxAge()) {
|
||||
if (null !== $maxAge = $this->getMaxAge()) {
|
||||
return $maxAge - $this->getAge();
|
||||
}
|
||||
|
||||
@@ -796,7 +815,9 @@ class Response
|
||||
/**
|
||||
* Returns the Last-Modified HTTP header as a DateTime instance.
|
||||
*
|
||||
* @return \DateTime A DateTime instance
|
||||
* @return \DateTime|null A DateTime instance or null if the header does not exist
|
||||
*
|
||||
* @throws \RuntimeException When the HTTP header is not parseable
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -808,9 +829,9 @@ class Response
|
||||
/**
|
||||
* Sets the Last-Modified HTTP header with a DateTime instance.
|
||||
*
|
||||
* If passed a null value, it removes the header.
|
||||
* Passing null as value will remove the header.
|
||||
*
|
||||
* @param \DateTime $date A \DateTime instance
|
||||
* @param \DateTime|null $date A \DateTime instance or null to remove the header
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
@@ -832,7 +853,7 @@ class Response
|
||||
/**
|
||||
* Returns the literal value of the ETag HTTP header.
|
||||
*
|
||||
* @return string The ETag HTTP header
|
||||
* @return string|null The ETag HTTP header or null if it does not exist
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -844,8 +865,8 @@ class Response
|
||||
/**
|
||||
* Sets the ETag value.
|
||||
*
|
||||
* @param string $etag The ETag unique identifier
|
||||
* @param Boolean $weak Whether you want a weak ETag or not
|
||||
* @param string|null $etag The ETag unique identifier or null to remove the header
|
||||
* @param Boolean $weak Whether you want a weak ETag or not
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
@@ -875,6 +896,8 @@ class Response
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setCache(array $options)
|
||||
@@ -952,7 +975,7 @@ class Response
|
||||
*/
|
||||
public function hasVary()
|
||||
{
|
||||
return (Boolean) $this->headers->get('Vary');
|
||||
return null !== $this->headers->get('Vary');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1108,7 +1131,7 @@ class Response
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the reponse forbidden?
|
||||
* Is the response forbidden?
|
||||
*
|
||||
* @return Boolean
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user