changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\HttpFoundation;
|
|
|
|
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
/**
|
|
|
|
* ResponseHeaderBag is a container for Response HTTP headers.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
*/
|
|
|
|
class ResponseHeaderBag extends HeaderBag
|
|
|
|
{
|
2014-10-22 19:27:13 +01:00
|
|
|
const COOKIES_FLAT = 'flat';
|
|
|
|
const COOKIES_ARRAY = 'array';
|
2011-09-08 10:20:37 +01:00
|
|
|
|
|
|
|
const DISPOSITION_ATTACHMENT = 'attachment';
|
2014-10-22 19:27:13 +01:00
|
|
|
const DISPOSITION_INLINE = 'inline';
|
2011-07-11 21:54:08 +01:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
protected $computedCacheControl = array();
|
2011-12-18 13:33:54 +00:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-10-22 19:27:13 +01:00
|
|
|
protected $cookies = array();
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
|
2012-10-04 13:45:19 +01:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2014-10-22 19:27:13 +01:00
|
|
|
protected $headerNames = array();
|
2012-10-04 13:45:19 +01:00
|
|
|
|
2011-01-31 14:08:49 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param array $headers An array of HTTP headers
|
|
|
|
*/
|
2011-02-11 16:57:07 +00:00
|
|
|
public function __construct(array $headers = array())
|
2011-01-31 14:08:49 +00:00
|
|
|
{
|
2011-02-15 19:30:31 +00:00
|
|
|
parent::__construct($headers);
|
2011-01-31 14:08:49 +00:00
|
|
|
|
2011-02-15 19:30:31 +00:00
|
|
|
if (!isset($this->headers['cache-control'])) {
|
2012-10-04 13:45:19 +01:00
|
|
|
$this->set('Cache-Control', '');
|
2011-02-15 19:30:31 +00:00
|
|
|
}
|
2011-01-31 14:08:49 +00:00
|
|
|
}
|
2011-06-08 11:12:55 +01:00
|
|
|
|
2011-05-19 08:49:34 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
$cookies = '';
|
2011-07-11 21:54:08 +01:00
|
|
|
foreach ($this->getCookies() as $cookie) {
|
2011-05-19 08:49:34 +01:00
|
|
|
$cookies .= 'Set-Cookie: '.$cookie."\r\n";
|
|
|
|
}
|
|
|
|
|
2013-02-26 08:53:49 +00:00
|
|
|
ksort($this->headerNames);
|
|
|
|
|
2011-05-19 16:38:16 +01:00
|
|
|
return parent::__toString().$cookies;
|
2011-05-19 08:49:34 +01:00
|
|
|
}
|
2011-01-31 14:08:49 +00:00
|
|
|
|
2012-10-04 13:45:19 +01:00
|
|
|
/**
|
|
|
|
* Returns the headers, with original capitalizations.
|
|
|
|
*
|
|
|
|
* @return array An array of headers
|
|
|
|
*/
|
|
|
|
public function allPreserveCase()
|
|
|
|
{
|
|
|
|
return array_combine($this->headerNames, $this->headers);
|
|
|
|
}
|
|
|
|
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function replace(array $headers = array())
|
|
|
|
{
|
2012-10-04 13:45:19 +01:00
|
|
|
$this->headerNames = array();
|
|
|
|
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
parent::replace($headers);
|
|
|
|
|
|
|
|
if (!isset($this->headers['cache-control'])) {
|
2012-10-04 13:45:19 +01:00
|
|
|
$this->set('Cache-Control', '');
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function set($key, $values, $replace = true)
|
|
|
|
{
|
|
|
|
parent::set($key, $values, $replace);
|
|
|
|
|
2016-01-06 13:34:50 +00:00
|
|
|
$uniqueKey = str_replace('_', '-', strtolower($key));
|
2012-10-04 13:45:19 +01:00
|
|
|
$this->headerNames[$uniqueKey] = $key;
|
|
|
|
|
2011-01-09 18:51:57 +00:00
|
|
|
// ensure the cache-control header has sensible defaults
|
2012-10-04 13:45:19 +01:00
|
|
|
if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) {
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
$computed = $this->computeCacheControlValue();
|
|
|
|
$this->headers['cache-control'] = array($computed);
|
2012-10-04 13:45:19 +01:00
|
|
|
$this->headerNames['cache-control'] = 'Cache-Control';
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
$this->computedCacheControl = $this->parseCacheControl($computed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2010-11-23 08:42:19 +00:00
|
|
|
public function remove($key)
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
{
|
2010-11-23 08:42:19 +00:00
|
|
|
parent::remove($key);
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
|
2016-01-06 13:34:50 +00:00
|
|
|
$uniqueKey = str_replace('_', '-', strtolower($key));
|
2012-10-04 13:45:19 +01:00
|
|
|
unset($this->headerNames[$uniqueKey]);
|
|
|
|
|
|
|
|
if ('cache-control' === $uniqueKey) {
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
$this->computedCacheControl = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-01-15 17:53:30 +00:00
|
|
|
public function hasCacheControlDirective($key)
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
{
|
2011-01-15 17:53:30 +00:00
|
|
|
return array_key_exists($key, $this->computedCacheControl);
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2011-01-15 17:53:30 +00:00
|
|
|
public function getCacheControlDirective($key)
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
{
|
2011-01-15 17:53:30 +00:00
|
|
|
return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
}
|
|
|
|
|
2011-07-04 19:46:58 +01:00
|
|
|
/**
|
|
|
|
* Sets a cookie.
|
|
|
|
*
|
|
|
|
* @param Cookie $cookie
|
|
|
|
*/
|
|
|
|
public function setCookie(Cookie $cookie)
|
|
|
|
{
|
2011-07-11 21:54:08 +01:00
|
|
|
$this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
|
2011-07-04 19:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Removes a cookie from the array, but does not unset it in the browser.
|
2011-07-04 19:46:58 +01:00
|
|
|
*
|
|
|
|
* @param string $name
|
2011-07-11 21:54:08 +01:00
|
|
|
* @param string $path
|
|
|
|
* @param string $domain
|
2011-07-04 19:46:58 +01:00
|
|
|
*/
|
2011-08-02 18:29:35 +01:00
|
|
|
public function removeCookie($name, $path = '/', $domain = null)
|
2011-07-04 19:46:58 +01:00
|
|
|
{
|
2011-09-28 09:34:14 +01:00
|
|
|
if (null === $path) {
|
|
|
|
$path = '/';
|
|
|
|
}
|
|
|
|
|
2011-07-11 21:54:08 +01:00
|
|
|
unset($this->cookies[$domain][$path][$name]);
|
2011-07-04 19:46:58 +01:00
|
|
|
|
2011-07-11 21:54:08 +01:00
|
|
|
if (empty($this->cookies[$domain][$path])) {
|
|
|
|
unset($this->cookies[$domain][$path]);
|
|
|
|
|
|
|
|
if (empty($this->cookies[$domain])) {
|
|
|
|
unset($this->cookies[$domain]);
|
|
|
|
}
|
|
|
|
}
|
2011-07-04 19:46:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Returns an array with all cookies.
|
2011-07-04 19:46:58 +01:00
|
|
|
*
|
2011-07-11 21:54:08 +01:00
|
|
|
* @param string $format
|
2011-07-04 19:46:58 +01:00
|
|
|
*
|
2011-07-11 21:54:08 +01:00
|
|
|
* @throws \InvalidArgumentException When the $format is invalid
|
2011-07-04 19:46:58 +01:00
|
|
|
*
|
2011-07-11 21:54:08 +01:00
|
|
|
* @return array
|
2011-07-04 19:46:58 +01:00
|
|
|
*/
|
2011-07-13 13:10:50 +01:00
|
|
|
public function getCookies($format = self::COOKIES_FLAT)
|
2011-07-04 19:46:58 +01:00
|
|
|
{
|
2011-07-13 13:10:50 +01:00
|
|
|
if (!in_array($format, array(self::COOKIES_FLAT, self::COOKIES_ARRAY))) {
|
|
|
|
throw new \InvalidArgumentException(sprintf('Format "%s" invalid (%s).', $format, implode(', ', array(self::COOKIES_FLAT, self::COOKIES_ARRAY))));
|
2011-07-04 19:46:58 +01:00
|
|
|
}
|
|
|
|
|
2011-07-13 13:10:50 +01:00
|
|
|
if (self::COOKIES_ARRAY === $format) {
|
2011-07-11 21:54:08 +01:00
|
|
|
return $this->cookies;
|
|
|
|
}
|
2011-07-04 19:46:58 +01:00
|
|
|
|
2011-07-13 13:10:50 +01:00
|
|
|
$flattenedCookies = array();
|
2011-07-11 21:54:08 +01:00
|
|
|
foreach ($this->cookies as $path) {
|
|
|
|
foreach ($path as $cookies) {
|
|
|
|
foreach ($cookies as $cookie) {
|
2011-07-13 13:10:50 +01:00
|
|
|
$flattenedCookies[] = $cookie;
|
2011-07-11 21:54:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-13 13:10:50 +01:00
|
|
|
return $flattenedCookies;
|
2011-07-04 19:46:58 +01:00
|
|
|
}
|
|
|
|
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Clears a cookie in the browser.
|
2011-01-15 17:53:30 +00:00
|
|
|
*
|
|
|
|
* @param string $name
|
2011-01-25 13:41:09 +00:00
|
|
|
* @param string $path
|
|
|
|
* @param string $domain
|
2014-06-19 19:53:04 +01:00
|
|
|
* @param bool $secure
|
|
|
|
* @param bool $httpOnly
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
*/
|
2014-06-19 19:53:04 +01:00
|
|
|
public function clearCookie($name, $path = '/', $domain = null, $secure = false, $httpOnly = true)
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
{
|
2014-06-19 19:53:04 +01:00
|
|
|
$this->setCookie(new Cookie($name, null, 1, $path, $domain, $secure, $httpOnly));
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-02 14:54:04 +01:00
|
|
|
/**
|
|
|
|
* Generates a HTTP Content-Disposition field-value.
|
|
|
|
*
|
|
|
|
* @param string $disposition One of "inline" or "attachment"
|
|
|
|
* @param string $filename A unicode string
|
|
|
|
* @param string $filenameFallback A string containing only ASCII characters that
|
|
|
|
* is semantically equivalent to $filename. If the filename is already ASCII,
|
|
|
|
* it can be omitted, or just copied from $filename
|
|
|
|
*
|
|
|
|
* @return string A string suitable for use as a Content-Disposition field-value.
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
2014-12-21 17:00:50 +00:00
|
|
|
*
|
2011-09-02 14:54:04 +01:00
|
|
|
* @see RFC 6266
|
|
|
|
*/
|
|
|
|
public function makeDisposition($disposition, $filename, $filenameFallback = '')
|
|
|
|
{
|
2011-09-08 10:20:37 +01:00
|
|
|
if (!in_array($disposition, array(self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE))) {
|
|
|
|
throw new \InvalidArgumentException(sprintf('The disposition must be either "%s" or "%s".', self::DISPOSITION_ATTACHMENT, self::DISPOSITION_INLINE));
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:28:33 +01:00
|
|
|
if ('' == $filenameFallback) {
|
2011-09-02 14:54:04 +01:00
|
|
|
$filenameFallback = $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
// filenameFallback is not ASCII.
|
|
|
|
if (!preg_match('/^[\x20-\x7e]*$/', $filenameFallback)) {
|
|
|
|
throw new \InvalidArgumentException('The filename fallback must only contain ASCII characters.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// percent characters aren't safe in fallback.
|
|
|
|
if (false !== strpos($filenameFallback, '%')) {
|
|
|
|
throw new \InvalidArgumentException('The filename fallback cannot contain the "%" character.');
|
|
|
|
}
|
|
|
|
|
|
|
|
// path separators aren't allowed in either.
|
2012-07-18 16:28:33 +01:00
|
|
|
if (false !== strpos($filename, '/') || false !== strpos($filename, '\\') || false !== strpos($filenameFallback, '/') || false !== strpos($filenameFallback, '\\')) {
|
2011-09-02 14:54:04 +01:00
|
|
|
throw new \InvalidArgumentException('The filename and the fallback cannot contain the "/" and "\\" characters.');
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:28:33 +01:00
|
|
|
$output = sprintf('%s; filename="%s"', $disposition, str_replace('"', '\\"', $filenameFallback));
|
2011-09-02 14:54:04 +01:00
|
|
|
|
2012-07-18 16:28:33 +01:00
|
|
|
if ($filename !== $filenameFallback) {
|
|
|
|
$output .= sprintf("; filename*=utf-8''%s", rawurlencode($filename));
|
2011-09-02 14:54:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2011-01-09 18:51:57 +00:00
|
|
|
/**
|
|
|
|
* Returns the calculated value of the cache-control header.
|
|
|
|
*
|
|
|
|
* This considers several other headers and calculates or modifies the
|
|
|
|
* cache-control header to a sensible, conservative value.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
protected function computeCacheControlValue()
|
|
|
|
{
|
|
|
|
if (!$this->cacheControl && !$this->has('ETag') && !$this->has('Last-Modified') && !$this->has('Expires')) {
|
|
|
|
return 'no-cache';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->cacheControl) {
|
|
|
|
// conservative by default
|
2011-02-16 15:36:12 +00:00
|
|
|
return 'private, must-revalidate';
|
changed Cache-Control default value behavior
The PHP native cache limiter feature has been disabled as this is now managed
by the HeaderBag class directly instead (see below.)
The HeaderBag class uses the following rules to define a sensible and
convervative default value for the Response 'Cache-Control' header:
* If no cache header is defined ('Cache-Control', 'ETag', 'Last-Modified',
and 'Expires'), 'Cache-Control' is set to 'no-cache';
* If 'Cache-Control' is empty, its value is set to "private, max-age=0,
must-revalidate";
* But if at least one 'Cache-Control' directive is set, and no 'public' or
'private' directives have been explicitely added, Symfony2 adds the
'private' directive automatically (except when 's-maxage' is set.)
So, remember to explicitly add the 'public' directive to 'Cache-Control' when
you want shared caches to store your application resources:
// The Response is private by default
$response->setEtag($etag);
$response->setLastModified($date);
$response->setMaxAge(10);
// Change the Response to be public
$response->setPublic();
// Set cache settings in one call
$response->setCache(array(
'etag' => $etag,
'last_modified' => $date,
'max_age' => 10,
'public' => true,
));
2010-11-10 09:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$header = $this->getCacheControlHeader();
|
|
|
|
if (isset($this->cacheControl['public']) || isset($this->cacheControl['private'])) {
|
|
|
|
return $header;
|
|
|
|
}
|
|
|
|
|
|
|
|
// public if s-maxage is defined, private otherwise
|
|
|
|
if (!isset($this->cacheControl['s-maxage'])) {
|
|
|
|
return $header.', private';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $header;
|
|
|
|
}
|
2011-06-08 11:16:48 +01:00
|
|
|
}
|