2010-02-17 13:53:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony package.
|
2010-02-17 13:53:18 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-02-17 13:53:18 +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;
|
|
|
|
|
2010-02-17 13:53:18 +00:00
|
|
|
/**
|
2010-05-03 10:23:53 +01:00
|
|
|
* Response represents an HTTP response.
|
2010-02-17 13:53:18 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-02-17 13:53:18 +00:00
|
|
|
*/
|
2010-04-24 08:38:58 +01:00
|
|
|
class Response
|
2010-02-17 13:53:18 +00:00
|
|
|
{
|
2010-07-10 13:46:25 +01:00
|
|
|
/**
|
2011-01-09 18:51:06 +00:00
|
|
|
* @var \Symfony\Component\HttpFoundation\ResponseHeaderBag
|
2010-07-10 13:46:25 +01:00
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public $headers;
|
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $content;
|
2011-12-18 13:33:54 +00:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $version;
|
2011-12-18 13:33:54 +00:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var integer
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $statusCode;
|
2011-12-18 13:33:54 +00:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $statusText;
|
2011-12-18 13:33:54 +00:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2011-02-21 15:56:42 +00:00
|
|
|
protected $charset;
|
2010-05-06 12:25:53 +01:00
|
|
|
|
2011-11-02 15:42:51 +00:00
|
|
|
/**
|
|
|
|
* Status codes translation table.
|
|
|
|
*
|
2012-03-10 12:09:53 +00:00
|
|
|
* The list of codes is complete according to the
|
|
|
|
* {@link http://www.iana.org/assignments/http-status-codes/ Hypertext Transfer Protocol (HTTP) Status Code Registry}
|
|
|
|
* (last updated 2012-02-13).
|
|
|
|
*
|
|
|
|
* Unless otherwise noted, the status code is defined in RFC2616.
|
|
|
|
*
|
2011-11-02 15:42:51 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2012-07-09 13:50:58 +01:00
|
|
|
public static $statusTexts = array(
|
2010-05-06 12:25:53 +01:00
|
|
|
100 => 'Continue',
|
|
|
|
101 => 'Switching Protocols',
|
2012-03-10 12:09:53 +00:00
|
|
|
102 => 'Processing', // RFC2518
|
2010-05-06 12:25:53 +01:00
|
|
|
200 => 'OK',
|
|
|
|
201 => 'Created',
|
|
|
|
202 => 'Accepted',
|
|
|
|
203 => 'Non-Authoritative Information',
|
|
|
|
204 => 'No Content',
|
|
|
|
205 => 'Reset Content',
|
|
|
|
206 => 'Partial Content',
|
2012-03-10 12:09:53 +00:00
|
|
|
207 => 'Multi-Status', // RFC4918
|
|
|
|
208 => 'Already Reported', // RFC5842
|
|
|
|
226 => 'IM Used', // RFC3229
|
2010-05-06 12:25:53 +01:00
|
|
|
300 => 'Multiple Choices',
|
|
|
|
301 => 'Moved Permanently',
|
|
|
|
302 => 'Found',
|
|
|
|
303 => 'See Other',
|
|
|
|
304 => 'Not Modified',
|
|
|
|
305 => 'Use Proxy',
|
2012-03-10 12:09:53 +00:00
|
|
|
306 => 'Reserved',
|
2010-05-06 12:25:53 +01:00
|
|
|
307 => 'Temporary Redirect',
|
2012-03-29 11:05:33 +01:00
|
|
|
308 => 'Permanent Redirect', // RFC-reschke-http-status-308-07
|
2010-05-06 12:25:53 +01:00
|
|
|
400 => 'Bad Request',
|
|
|
|
401 => 'Unauthorized',
|
|
|
|
402 => 'Payment Required',
|
|
|
|
403 => 'Forbidden',
|
|
|
|
404 => 'Not Found',
|
|
|
|
405 => 'Method Not Allowed',
|
|
|
|
406 => 'Not Acceptable',
|
|
|
|
407 => 'Proxy Authentication Required',
|
|
|
|
408 => 'Request Timeout',
|
|
|
|
409 => 'Conflict',
|
|
|
|
410 => 'Gone',
|
|
|
|
411 => 'Length Required',
|
|
|
|
412 => 'Precondition Failed',
|
|
|
|
413 => 'Request Entity Too Large',
|
|
|
|
414 => 'Request-URI Too Long',
|
|
|
|
415 => 'Unsupported Media Type',
|
|
|
|
416 => 'Requested Range Not Satisfiable',
|
|
|
|
417 => 'Expectation Failed',
|
2012-05-05 09:20:38 +01:00
|
|
|
418 => 'I\'m a teapot', // RFC2324
|
2012-05-05 07:22:03 +01:00
|
|
|
422 => 'Unprocessable Entity', // RFC4918
|
|
|
|
423 => 'Locked', // RFC4918
|
|
|
|
424 => 'Failed Dependency', // RFC4918
|
2012-03-10 12:09:53 +00:00
|
|
|
425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
|
2012-05-05 07:22:03 +01:00
|
|
|
426 => 'Upgrade Required', // RFC2817
|
|
|
|
428 => 'Precondition Required', // RFC6585
|
|
|
|
429 => 'Too Many Requests', // RFC6585
|
|
|
|
431 => 'Request Header Fields Too Large', // RFC6585
|
2010-05-06 12:25:53 +01:00
|
|
|
500 => 'Internal Server Error',
|
|
|
|
501 => 'Not Implemented',
|
|
|
|
502 => 'Bad Gateway',
|
|
|
|
503 => 'Service Unavailable',
|
|
|
|
504 => 'Gateway Timeout',
|
|
|
|
505 => 'HTTP Version Not Supported',
|
2012-05-05 07:22:03 +01:00
|
|
|
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
|
|
|
|
507 => 'Insufficient Storage', // RFC4918
|
|
|
|
508 => 'Loop Detected', // RFC5842
|
|
|
|
510 => 'Not Extended', // RFC2774
|
|
|
|
511 => 'Network Authentication Required', // RFC6585
|
2010-05-06 12:25:53 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param string $content The response content
|
|
|
|
* @param integer $status The response status code
|
|
|
|
* @param array $headers An array of response headers
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function __construct($content = '', $status = 200, $headers = array())
|
|
|
|
{
|
2011-05-16 07:46:36 +01:00
|
|
|
$this->headers = new ResponseHeaderBag($headers);
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->setContent($content);
|
|
|
|
$this->setStatusCode($status);
|
|
|
|
$this->setProtocolVersion('1.0');
|
2011-05-16 07:46:36 +01:00
|
|
|
if (!$this->headers->has('Date')) {
|
|
|
|
$this->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
|
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
2012-03-15 15:22:55 +00:00
|
|
|
/**
|
|
|
|
* Factory method for chainability
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* return Response::create($body, 200)
|
|
|
|
* ->setSharedMaxAge(300);
|
|
|
|
*
|
|
|
|
* @param string $content The response content
|
|
|
|
* @param integer $status The response status code
|
|
|
|
* @param array $headers An array of response headers
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
|
|
|
*/
|
2012-07-09 13:50:58 +01:00
|
|
|
public static function create($content = '', $status = 200, $headers = array())
|
2012-03-15 15:22:55 +00:00
|
|
|
{
|
|
|
|
return new static($content, $status, $headers);
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2011-10-17 16:16:22 +01:00
|
|
|
* Returns the Response as an HTTP string.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2012-04-18 21:38:08 +01:00
|
|
|
* The string representation of the Response is the same as the
|
2011-10-17 16:16:22 +01:00
|
|
|
* one that will be sent to the client only if the prepare() method
|
|
|
|
* has been called before.
|
|
|
|
*
|
|
|
|
* @return string The Response as an HTTP string
|
|
|
|
*
|
|
|
|
* @see prepare()
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
2011-05-15 11:38:12 +01:00
|
|
|
return
|
|
|
|
sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n".
|
|
|
|
$this->headers."\r\n".
|
|
|
|
$this->getContent();
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clones the current Response instance.
|
|
|
|
*/
|
|
|
|
public function __clone()
|
|
|
|
{
|
|
|
|
$this->headers = clone $this->headers;
|
|
|
|
}
|
|
|
|
|
2011-07-11 10:21:18 +01:00
|
|
|
/**
|
|
|
|
* Prepares the Response before it is sent to the client.
|
|
|
|
*
|
|
|
|
* This method tweaks the Response to ensure that it is
|
2011-10-17 16:16:22 +01:00
|
|
|
* compliant with RFC 2616. Most of the changes are based on
|
|
|
|
* the Request that is "associated" with this Response.
|
|
|
|
*
|
|
|
|
* @param Request $request A Request instance
|
2012-04-16 00:30:07 +01:00
|
|
|
*
|
|
|
|
* @return Response The current response.
|
2011-07-11 10:21:18 +01:00
|
|
|
*/
|
2011-10-17 16:16:22 +01:00
|
|
|
public function prepare(Request $request)
|
2011-07-11 10:21:18 +01:00
|
|
|
{
|
2011-10-17 16:16:22 +01:00
|
|
|
$headers = $this->headers;
|
|
|
|
|
2011-07-11 10:21:18 +01:00
|
|
|
if ($this->isInformational() || in_array($this->statusCode, array(204, 304))) {
|
2012-06-13 15:20:50 +01:00
|
|
|
$this->setContent(null);
|
2011-07-11 10:21:18 +01:00
|
|
|
}
|
|
|
|
|
2011-10-17 16:16:22 +01:00
|
|
|
// Content-type based on the Request
|
|
|
|
if (!$headers->has('Content-Type')) {
|
|
|
|
$format = $request->getRequestFormat();
|
|
|
|
if (null !== $format && $mimeType = $request->getMimeType($format)) {
|
|
|
|
$headers->set('Content-Type', $mimeType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 10:21:18 +01:00
|
|
|
// Fix Content-Type
|
|
|
|
$charset = $this->charset ?: 'UTF-8';
|
2011-10-17 16:16:22 +01:00
|
|
|
if (!$headers->has('Content-Type')) {
|
|
|
|
$headers->set('Content-Type', 'text/html; charset='.$charset);
|
2012-01-16 06:44:08 +00:00
|
|
|
} elseif (0 === strpos($headers->get('Content-Type'), 'text/') && false === strpos($headers->get('Content-Type'), 'charset')) {
|
2011-07-11 10:21:18 +01:00
|
|
|
// add the charset
|
2011-10-17 16:16:22 +01:00
|
|
|
$headers->set('Content-Type', $headers->get('Content-Type').'; charset='.$charset);
|
2011-07-11 10:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fix Content-Length
|
2011-10-17 16:16:22 +01:00
|
|
|
if ($headers->has('Transfer-Encoding')) {
|
|
|
|
$headers->remove('Content-Length');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('HEAD' === $request->getMethod()) {
|
|
|
|
// cf. RFC2616 14.13
|
|
|
|
$length = $headers->get('Content-Length');
|
2012-06-13 15:20:50 +01:00
|
|
|
$this->setContent(null);
|
2011-10-17 16:16:22 +01:00
|
|
|
if ($length) {
|
|
|
|
$headers->set('Content-Length', $length);
|
|
|
|
}
|
2011-07-11 10:21:18 +01:00
|
|
|
}
|
2012-04-16 00:30:07 +01:00
|
|
|
|
2012-11-09 07:57:59 +00:00
|
|
|
// Fix protocol
|
|
|
|
if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
|
|
|
|
$this->setProtocolVersion('1.1');
|
|
|
|
}
|
|
|
|
|
2012-11-17 10:57:00 +00:00
|
|
|
// Check if we need to send extra expire info headers
|
|
|
|
if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) {
|
|
|
|
$this->headers->set('pragma', 'no-cache');
|
|
|
|
$this->headers->set('expires', -1);
|
|
|
|
}
|
|
|
|
|
2012-04-16 00:30:07 +01:00
|
|
|
return $this;
|
2011-07-11 10:21:18 +01:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
2010-06-23 15:24:24 +01:00
|
|
|
* Sends HTTP headers.
|
2012-03-15 15:22:55 +00:00
|
|
|
*
|
|
|
|
* @return Response
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function sendHeaders()
|
|
|
|
{
|
2011-07-07 06:31:02 +01:00
|
|
|
// headers have already been sent by the developer
|
|
|
|
if (headers_sent()) {
|
2012-03-15 15:22:55 +00:00
|
|
|
return $this;
|
2011-07-07 06:31:02 +01:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
// status
|
|
|
|
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText));
|
|
|
|
|
|
|
|
// headers
|
2010-06-23 15:24:24 +01:00
|
|
|
foreach ($this->headers->all() as $name => $values) {
|
|
|
|
foreach ($values as $value) {
|
2011-06-10 17:16:33 +01:00
|
|
|
header($name.': '.$value, false);
|
2010-06-23 15:24:24 +01:00
|
|
|
}
|
2010-02-17 13:53:18 +00:00
|
|
|
}
|
2011-01-15 17:53:30 +00:00
|
|
|
|
|
|
|
// cookies
|
|
|
|
foreach ($this->headers->getCookies() as $cookie) {
|
2011-04-13 19:09:04 +01:00
|
|
|
setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
|
2011-01-15 17:53:30 +00:00
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-02-17 13:53:18 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Sends content for the current web response.
|
2012-03-15 15:22:55 +00:00
|
|
|
*
|
|
|
|
* @return Response
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function sendContent()
|
|
|
|
{
|
|
|
|
echo $this->content;
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends HTTP headers and content.
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function send()
|
|
|
|
{
|
|
|
|
$this->sendHeaders();
|
|
|
|
$this->sendContent();
|
2011-06-13 17:54:20 +01:00
|
|
|
|
2011-06-09 19:11:02 +01:00
|
|
|
if (function_exists('fastcgi_finish_request')) {
|
|
|
|
fastcgi_finish_request();
|
2012-07-15 09:55:34 +01:00
|
|
|
} elseif ('cli' !== PHP_SAPI) {
|
2012-07-15 08:31:47 +01:00
|
|
|
// ob_get_level() never returns 0 on some Windows configurations, so if
|
|
|
|
// the level is the same two times in a row, the loop should be stopped.
|
|
|
|
$previous = null;
|
2012-07-24 16:11:14 +01:00
|
|
|
$obStatus = ob_get_status(1);
|
2012-07-15 08:31:47 +01:00
|
|
|
while (($level = ob_get_level()) > 0 && $level !== $previous) {
|
|
|
|
$previous = $level;
|
2012-07-25 08:38:36 +01:00
|
|
|
if ($obStatus[$level - 1] && isset($obStatus[$level - 1]['del']) && $obStatus[$level - 1]['del']) {
|
2012-07-24 16:11:14 +01:00
|
|
|
ob_end_flush();
|
|
|
|
}
|
2012-07-14 13:47:09 +01:00
|
|
|
}
|
|
|
|
flush();
|
2011-06-09 19:11:02 +01:00
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Sets the response content.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2011-06-21 12:06:36 +01:00
|
|
|
* Valid types are strings, numbers, and objects that implement a __toString() method.
|
|
|
|
*
|
|
|
|
* @param mixed $content
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setContent($content)
|
|
|
|
{
|
2011-06-22 14:23:37 +01:00
|
|
|
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable(array($content, '__toString'))) {
|
2011-06-21 12:06:36 +01:00
|
|
|
throw new \UnexpectedValueException('The Response content must be a string or object implementing __toString(), "'.gettype($content).'" given.');
|
2011-06-21 10:59:20 +01:00
|
|
|
}
|
2011-06-22 14:22:06 +01:00
|
|
|
|
|
|
|
$this->content = (string) $content;
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Gets the current response content.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @return string Content
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getContent()
|
|
|
|
{
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the HTTP protocol version (1.0 or 1.1).
|
|
|
|
*
|
|
|
|
* @param string $version The HTTP protocol version
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setProtocolVersion($version)
|
|
|
|
{
|
|
|
|
$this->version = $version;
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the HTTP protocol version.
|
|
|
|
*
|
|
|
|
* @return string The HTTP protocol version
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getProtocolVersion()
|
|
|
|
{
|
|
|
|
return $this->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Sets the response status code.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @param integer $code HTTP status code
|
2012-07-19 16:48:12 +01:00
|
|
|
* @param mixed $text HTTP status text
|
|
|
|
*
|
|
|
|
* If the status text is null it will be automatically populated for the known
|
|
|
|
* status codes and left empty otherwise.
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When the HTTP status code is not valid
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setStatusCode($code, $text = null)
|
|
|
|
{
|
2012-07-19 16:48:12 +01:00
|
|
|
$this->statusCode = $code = (int) $code;
|
2011-03-05 13:27:35 +00:00
|
|
|
if ($this->isInvalid()) {
|
2010-05-06 12:25:53 +01:00
|
|
|
throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
|
|
|
|
}
|
|
|
|
|
2012-07-19 16:48:12 +01:00
|
|
|
if (null === $text) {
|
|
|
|
$this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : '';
|
|
|
|
|
2012-07-20 06:34:13 +01:00
|
|
|
return $this;
|
2012-07-19 16:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (false === $text) {
|
|
|
|
$this->statusText = '';
|
|
|
|
|
2012-07-20 06:34:13 +01:00
|
|
|
return $this;
|
2012-07-19 16:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->statusText = $text;
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Retrieves the status code for the current web response.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @return string Status code
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getStatusCode()
|
|
|
|
{
|
|
|
|
return $this->statusCode;
|
|
|
|
}
|
|
|
|
|
2010-12-15 11:10:29 +00:00
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Sets the response charset.
|
2010-12-15 11:10:29 +00:00
|
|
|
*
|
|
|
|
* @param string $charset Character set
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-12-15 11:10:29 +00:00
|
|
|
*/
|
|
|
|
public function setCharset($charset)
|
|
|
|
{
|
|
|
|
$this->charset = $charset;
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-12-15 11:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the response charset.
|
|
|
|
*
|
|
|
|
* @return string Character set
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-12-15 11:10:29 +00:00
|
|
|
*/
|
|
|
|
public function getCharset()
|
|
|
|
{
|
|
|
|
return $this->charset;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the response is worth caching under any circumstance.
|
|
|
|
*
|
|
|
|
* Responses marked "private" with an explicit Cache-Control directive are
|
|
|
|
* considered uncacheable.
|
|
|
|
*
|
|
|
|
* Responses with neither a freshness lifetime (Expires, max-age) nor cache
|
|
|
|
* validator (Last-Modified, ETag) are considered uncacheable.
|
|
|
|
*
|
|
|
|
* @return Boolean true if the response is worth caching, false otherwise
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function isCacheable()
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (!in_array($this->statusCode, array(200, 203, 300, 301, 302, 404, 410))) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if ($this->headers->hasCacheControlDirective('no-store') || $this->headers->getCacheControlDirective('private')) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->isValidateable() || $this->isFresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the response is "fresh".
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @return Boolean true if the response is fresh, false otherwise
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function isFresh()
|
|
|
|
{
|
|
|
|
return $this->getTtl() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the response includes headers that can be used to validate
|
|
|
|
* the response with the origin server using a conditional GET request.
|
|
|
|
*
|
|
|
|
* @return Boolean true if the response is validateable, false otherwise
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function isValidateable()
|
|
|
|
{
|
|
|
|
return $this->headers->has('Last-Modified') || $this->headers->has('ETag');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-11-12 18:45:28 +00:00
|
|
|
* Marks the response as "private".
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* It makes the response ineligible for serving other clients.
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
2010-11-12 18:45:28 +00:00
|
|
|
*/
|
|
|
|
public function setPrivate()
|
|
|
|
{
|
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->headers->removeCacheControlDirective('public');
|
|
|
|
$this->headers->addCacheControlDirective('private');
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-11-12 18:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the response as "public".
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2010-11-12 18:45:28 +00:00
|
|
|
* It makes the response eligible for serving other clients.
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
2010-11-12 18:45:28 +00:00
|
|
|
public function setPublic()
|
2010-05-06 12:25:53 +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
|
|
|
$this->headers->addCacheControlDirective('public');
|
|
|
|
$this->headers->removeCacheControlDirective('private');
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the response must be revalidated by caches.
|
|
|
|
*
|
|
|
|
* This method indicates that the response must not be served stale by a
|
|
|
|
* cache in any circumstance without first revalidating with the origin.
|
2010-10-16 11:32:57 +01:00
|
|
|
* When present, the TTL of the response should not be overridden to be
|
2010-05-06 12:25:53 +01:00
|
|
|
* greater than the value provided by the origin.
|
|
|
|
*
|
|
|
|
* @return Boolean true if the response must be revalidated by a cache, false otherwise
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function mustRevalidate()
|
|
|
|
{
|
2012-05-16 10:17:19 +01:00
|
|
|
return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('proxy-revalidate');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Date header as a DateTime instance.
|
|
|
|
*
|
|
|
|
* @return \DateTime A \DateTime instance
|
|
|
|
*
|
2012-01-05 22:17:04 +00:00
|
|
|
* @throws \RuntimeException When the header is not parseable
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getDate()
|
|
|
|
{
|
2012-09-30 09:47:54 +01:00
|
|
|
return $this->headers->getDate('Date', new \DateTime());
|
2011-05-16 07:46:36 +01:00
|
|
|
}
|
2010-05-06 12:25:53 +01:00
|
|
|
|
2011-05-16 07:46:36 +01:00
|
|
|
/**
|
|
|
|
* Sets the Date header.
|
|
|
|
*
|
|
|
|
* @param \DateTime $date A \DateTime instance
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2011-05-16 07:46:36 +01:00
|
|
|
*/
|
|
|
|
public function setDate(\DateTime $date)
|
|
|
|
{
|
|
|
|
$date->setTimezone(new \DateTimeZone('UTC'));
|
|
|
|
$this->headers->set('Date', $date->format('D, d M Y H:i:s').' GMT');
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the age of the response.
|
|
|
|
*
|
|
|
|
* @return integer The age of the response in seconds
|
|
|
|
*/
|
|
|
|
public function getAge()
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($age = $this->headers->get('Age')) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return $age;
|
|
|
|
}
|
|
|
|
|
|
|
|
return max(time() - $this->getDate()->format('U'), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the response stale by setting the Age header to be equal to the maximum age of the response.
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function expire()
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($this->isFresh()) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->headers->set('Age', $this->getMaxAge());
|
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value of the Expires header as a DateTime instance.
|
|
|
|
*
|
|
|
|
* @return \DateTime A DateTime instance
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getExpires()
|
|
|
|
{
|
|
|
|
return $this->headers->getDate('Expires');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Sets the Expires HTTP header with a DateTime instance.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2010-11-23 08:42:19 +00:00
|
|
|
* If passed a null value, it removes the header.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @param \DateTime $date A \DateTime instance
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setExpires(\DateTime $date = null)
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (null === $date) {
|
2010-11-23 08:42:19 +00:00
|
|
|
$this->headers->remove('Expires');
|
2010-05-07 15:09:11 +01:00
|
|
|
} else {
|
2010-10-27 09:56:56 +01:00
|
|
|
$date = clone $date;
|
|
|
|
$date->setTimezone(new \DateTimeZone('UTC'));
|
|
|
|
$this->headers->set('Expires', $date->format('D, d M Y H:i:s').' GMT');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets 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
|
|
|
|
* back on an expires header. It returns null when no maximum age can be established.
|
|
|
|
*
|
|
|
|
* @return integer|null Number of seconds
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getMaxAge()
|
|
|
|
{
|
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
|
|
|
if ($age = $this->headers->getCacheControlDirective('s-maxage')) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return $age;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if ($age = $this->headers->getCacheControlDirective('max-age')) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return $age;
|
|
|
|
}
|
|
|
|
|
2012-12-11 09:29:04 +00:00
|
|
|
if (null !== $this->getExpires()) {
|
2012-12-22 23:33:31 +00:00
|
|
|
if (!$this->getExpires() instanceof \DateTime) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-11 09:29:04 +00:00
|
|
|
return $this->getExpires()->format('U') - $this->getDate()->format('U');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the number of seconds after which the response should no longer be considered fresh.
|
|
|
|
*
|
|
|
|
* This methods sets the Cache-Control max-age directive.
|
|
|
|
*
|
2012-01-05 22:17:04 +00:00
|
|
|
* @param integer $value Number of seconds
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setMaxAge($value)
|
|
|
|
{
|
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->headers->addCacheControlDirective('max-age', $value);
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the number of seconds after which the response should no longer be considered fresh by shared caches.
|
|
|
|
*
|
|
|
|
* This methods sets the Cache-Control s-maxage directive.
|
|
|
|
*
|
2012-01-05 22:17:04 +00:00
|
|
|
* @param integer $value Number of seconds
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setSharedMaxAge($value)
|
|
|
|
{
|
2011-04-13 14:58:48 +01:00
|
|
|
$this->setPublic();
|
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->headers->addCacheControlDirective('s-maxage', $value);
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the response's time-to-live in seconds.
|
|
|
|
*
|
|
|
|
* It returns null when no freshness information is present in the response.
|
|
|
|
*
|
|
|
|
* When the responses TTL is <= 0, the response may not be served from cache without first
|
|
|
|
* revalidating with the origin.
|
|
|
|
*
|
2012-06-25 17:21:41 +01:00
|
|
|
* @return integer|null The TTL in seconds
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getTtl()
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($maxAge = $this->getMaxAge()) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return $maxAge - $this->getAge();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the response's time-to-live for shared caches.
|
|
|
|
*
|
|
|
|
* This method adjusts the Cache-Control/s-maxage directive.
|
|
|
|
*
|
2012-01-05 22:17:04 +00:00
|
|
|
* @param integer $seconds Number of seconds
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setTtl($seconds)
|
|
|
|
{
|
|
|
|
$this->setSharedMaxAge($this->getAge() + $seconds);
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the response's time-to-live for private/client caches.
|
|
|
|
*
|
|
|
|
* This method adjusts the Cache-Control/max-age directive.
|
|
|
|
*
|
2012-01-05 22:17:04 +00:00
|
|
|
* @param integer $seconds Number of seconds
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setClientTtl($seconds)
|
|
|
|
{
|
|
|
|
$this->setMaxAge($this->getAge() + $seconds);
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Last-Modified HTTP header as a DateTime instance.
|
|
|
|
*
|
|
|
|
* @return \DateTime A DateTime instance
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getLastModified()
|
|
|
|
{
|
2011-03-05 23:17:54 +00:00
|
|
|
return $this->headers->getDate('Last-Modified');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Sets the Last-Modified HTTP header with a DateTime instance.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
2010-11-23 08:42:19 +00:00
|
|
|
* If passed a null value, it removes the header.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @param \DateTime $date A \DateTime instance
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setLastModified(\DateTime $date = null)
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (null === $date) {
|
2010-11-23 08:42:19 +00:00
|
|
|
$this->headers->remove('Last-Modified');
|
2010-05-07 15:09:11 +01:00
|
|
|
} else {
|
2010-10-27 09:56:56 +01:00
|
|
|
$date = clone $date;
|
|
|
|
$date->setTimezone(new \DateTimeZone('UTC'));
|
|
|
|
$this->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Returns the literal value of the ETag HTTP header.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @return string The ETag HTTP header
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getEtag()
|
2010-05-03 10:47:01 +01:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return $this->headers->get('ETag');
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:46:22 +00:00
|
|
|
/**
|
|
|
|
* Sets the ETag value.
|
|
|
|
*
|
|
|
|
* @param string $etag The ETag unique identifier
|
|
|
|
* @param Boolean $weak Whether you want a weak ETag or not
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-11-12 18:46:22 +00:00
|
|
|
*/
|
2010-05-19 10:24:31 +01:00
|
|
|
public function setEtag($etag = null, $weak = false)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (null === $etag) {
|
2010-11-23 08:42:19 +00:00
|
|
|
$this->headers->remove('Etag');
|
2010-05-07 15:09:11 +01:00
|
|
|
} else {
|
2010-05-19 10:24:31 +01:00
|
|
|
if (0 !== strpos($etag, '"')) {
|
|
|
|
$etag = '"'.$etag.'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->headers->set('ETag', (true === $weak ? 'W/' : '').$etag);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-12 18:46:39 +00:00
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Sets the response's cache headers (validation and/or expiration).
|
2010-11-12 18:46:39 +00:00
|
|
|
*
|
2010-11-12 18:49:01 +00:00
|
|
|
* Available options are: etag, last_modified, max_age, s_maxage, private, and public.
|
2010-11-12 18:46:39 +00:00
|
|
|
*
|
|
|
|
* @param array $options An array of cache options
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-11-12 18:46:39 +00:00
|
|
|
*/
|
|
|
|
public function setCache(array $options)
|
|
|
|
{
|
2011-01-30 19:13:00 +00:00
|
|
|
if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'))) {
|
2012-01-16 21:09:07 +00:00
|
|
|
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
|
2010-11-12 18:46:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['etag'])) {
|
|
|
|
$this->setEtag($options['etag']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['last_modified'])) {
|
|
|
|
$this->setLastModified($options['last_modified']);
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:49:01 +00:00
|
|
|
if (isset($options['max_age'])) {
|
|
|
|
$this->setMaxAge($options['max_age']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['s_maxage'])) {
|
|
|
|
$this->setSharedMaxAge($options['s_maxage']);
|
|
|
|
}
|
|
|
|
|
2010-11-12 18:46:39 +00:00
|
|
|
if (isset($options['public'])) {
|
|
|
|
if ($options['public']) {
|
|
|
|
$this->setPublic();
|
|
|
|
} else {
|
|
|
|
$this->setPrivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['private'])) {
|
|
|
|
if ($options['private']) {
|
|
|
|
$this->setPrivate();
|
|
|
|
} else {
|
|
|
|
$this->setPublic();
|
|
|
|
}
|
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-11-12 18:46:39 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Modifies the response so that it conforms to the rules defined for a 304 status code.
|
|
|
|
*
|
|
|
|
* This sets the status, removes the body, and discards any headers
|
|
|
|
* that MUST NOT be included in 304 responses.
|
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
|
|
|
*
|
2010-05-06 12:25:53 +01:00
|
|
|
* @see http://tools.ietf.org/html/rfc2616#section-10.3.5
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function setNotModified()
|
|
|
|
{
|
|
|
|
$this->setStatusCode(304);
|
|
|
|
$this->setContent(null);
|
|
|
|
|
|
|
|
// remove headers that MUST NOT be included with 304 Not Modified responses
|
2010-05-07 15:09:11 +01:00
|
|
|
foreach (array('Allow', 'Content-Encoding', 'Content-Language', 'Content-Length', 'Content-MD5', 'Content-Type', 'Last-Modified') as $header) {
|
2010-11-23 08:42:19 +00:00
|
|
|
$this->headers->remove($header);
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the response includes a Vary header.
|
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean true if the response includes a Vary header, false otherwise
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function hasVary()
|
|
|
|
{
|
|
|
|
return (Boolean) $this->headers->get('Vary');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of header names given in the Vary header.
|
|
|
|
*
|
|
|
|
* @return array An array of Vary names
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function getVary()
|
|
|
|
{
|
2010-05-07 15:09:11 +01:00
|
|
|
if (!$vary = $this->headers->get('Vary')) {
|
2010-05-06 12:25:53 +01:00
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2010-10-30 15:37:18 +01:00
|
|
|
return is_array($vary) ? $vary : preg_split('/[\s,]+/', $vary);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Vary header.
|
|
|
|
*
|
|
|
|
* @param string|array $headers
|
2012-05-18 18:41:48 +01:00
|
|
|
* @param Boolean $replace Whether to replace the actual value of not (true by default)
|
2012-03-15 16:41:21 +00:00
|
|
|
*
|
2012-03-15 15:22:55 +00:00
|
|
|
* @return Response
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-10-30 15:37:18 +01:00
|
|
|
*/
|
|
|
|
public function setVary($headers, $replace = true)
|
|
|
|
{
|
|
|
|
$this->headers->set('Vary', $headers, $replace);
|
2012-03-15 15:22:55 +00:00
|
|
|
|
|
|
|
return $this;
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-01-05 22:17:04 +00:00
|
|
|
* Determines if the Response validators (ETag, Last-Modified) match
|
2010-05-06 12:25:53 +01:00
|
|
|
* a conditional value specified in the Request.
|
|
|
|
*
|
|
|
|
* If the Response is not modified, it sets the status code to 304 and
|
2012-01-05 22:17:04 +00:00
|
|
|
* removes the actual content by calling the setNotModified() method.
|
2010-05-06 12:25:53 +01:00
|
|
|
*
|
|
|
|
* @param Request $request A Request instance
|
|
|
|
*
|
2012-01-05 22:17:04 +00:00
|
|
|
* @return Boolean true if the Response validators match the Request, false otherwise
|
2011-07-20 09:06:02 +01:00
|
|
|
*
|
|
|
|
* @api
|
2010-05-06 12:25:53 +01:00
|
|
|
*/
|
|
|
|
public function isNotModified(Request $request)
|
|
|
|
{
|
2012-07-21 20:52:19 +01:00
|
|
|
if (!$request->isMethodSafe()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$lastModified = $request->headers->get('If-Modified-Since');
|
|
|
|
$notModified = false;
|
2010-05-19 10:24:31 +01:00
|
|
|
if ($etags = $request->getEtags()) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$notModified = (in_array($this->getEtag(), $etags) || in_array('*', $etags)) && (!$lastModified || $this->headers->get('Last-Modified') == $lastModified);
|
2010-05-07 15:09:11 +01:00
|
|
|
} elseif ($lastModified) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$notModified = $lastModified == $this->headers->get('Last-Modified');
|
|
|
|
}
|
|
|
|
|
2010-05-07 15:09:11 +01:00
|
|
|
if ($notModified) {
|
2010-05-06 12:25:53 +01:00
|
|
|
$this->setNotModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notModified;
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-03 05:37:03 +00:00
|
|
|
* Is response invalid?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isInvalid()
|
|
|
|
{
|
|
|
|
return $this->statusCode < 100 || $this->statusCode >= 600;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is response informative?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isInformational()
|
|
|
|
{
|
|
|
|
return $this->statusCode >= 100 && $this->statusCode < 200;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is response successful?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isSuccessful()
|
|
|
|
{
|
|
|
|
return $this->statusCode >= 200 && $this->statusCode < 300;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is the response a redirect?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isRedirection()
|
|
|
|
{
|
|
|
|
return $this->statusCode >= 300 && $this->statusCode < 400;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is there a client error?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isClientError()
|
|
|
|
{
|
|
|
|
return $this->statusCode >= 400 && $this->statusCode < 500;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Was there a server side error?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isServerError()
|
|
|
|
{
|
|
|
|
return $this->statusCode >= 500 && $this->statusCode < 600;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is the response OK?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isOk()
|
|
|
|
{
|
|
|
|
return 200 === $this->statusCode;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is the reponse forbidden?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isForbidden()
|
|
|
|
{
|
|
|
|
return 403 === $this->statusCode;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is the response a not found error?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isNotFound()
|
|
|
|
{
|
|
|
|
return 404 === $this->statusCode;
|
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is the response a redirect of some form?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @param string $location
|
|
|
|
*
|
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2011-05-29 14:33:37 +01:00
|
|
|
public function isRedirect($location = null)
|
2010-05-06 12:25:53 +01:00
|
|
|
{
|
2012-06-09 23:20:06 +01:00
|
|
|
return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
|
2010-05-06 12:25:53 +01:00
|
|
|
}
|
|
|
|
|
2011-07-20 09:06:02 +01:00
|
|
|
/**
|
2011-11-02 15:42:51 +00:00
|
|
|
* Is the response empty?
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2012-02-12 01:04:15 +00:00
|
|
|
* @return Boolean
|
2011-12-18 13:33:54 +00:00
|
|
|
*
|
2011-07-20 09:06:02 +01:00
|
|
|
* @api
|
|
|
|
*/
|
2010-05-06 12:25:53 +01:00
|
|
|
public function isEmpty()
|
|
|
|
{
|
|
|
|
return in_array($this->statusCode, array(201, 204, 304));
|
|
|
|
}
|
2011-12-18 13:33:54 +00:00
|
|
|
}
|