Updated Symfony HttpFoundation to 2.1.6.

This commit is contained in:
Taylor Otwell
2013-01-06 13:58:32 -06:00
parent f754e1fa55
commit cb567c5e4d
55 changed files with 1758 additions and 805 deletions

View File

@@ -61,7 +61,7 @@ class Response
*
* @var array
*/
static public $statusTexts = array(
public static $statusTexts = array(
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing', // RFC2518
@@ -83,6 +83,7 @@ class Response
305 => 'Use Proxy',
306 => 'Reserved',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect', // RFC-reschke-http-status-308-07
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
@@ -101,26 +102,26 @@ class Response
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot',
422 => 'Unprocessable Entity', // RFC4918
423 => 'Locked', // RFC4918
424 => 'Failed Dependency', // RFC4918
418 => 'I\'m a teapot', // RFC2324
422 => 'Unprocessable Entity', // RFC4918
423 => 'Locked', // RFC4918
424 => 'Failed Dependency', // RFC4918
425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
426 => 'Upgrade Required', // RFC2817
428 => 'Precondition Required', // RFC-nottingham-http-new-status-04
429 => 'Too Many Requests', // RFC-nottingham-http-new-status-04
431 => 'Request Header Fields Too Large', // RFC-nottingham-http-new-status-04
426 => 'Upgrade Required', // RFC2817
428 => 'Precondition Required', // RFC6585
429 => 'Too Many Requests', // RFC6585
431 => 'Request Header Fields Too Large', // RFC6585
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates (Experimental)', // [RFC2295]
507 => 'Insufficient Storage', // RFC4918
508 => 'Loop Detected', // RFC5842
510 => 'Not Extended', // RFC2774
511 => 'Network Authentication Required', // RFC-nottingham-http-new-status-04
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
507 => 'Insufficient Storage', // RFC4918
508 => 'Loop Detected', // RFC5842
510 => 'Not Extended', // RFC2774
511 => 'Network Authentication Required', // RFC6585
);
/**
@@ -157,7 +158,7 @@ class Response
*
* @return Response
*/
static public function create($content = '', $status = 200, $headers = array())
public static function create($content = '', $status = 200, $headers = array())
{
return new static($content, $status, $headers);
}
@@ -165,7 +166,7 @@ class Response
/**
* Returns the Response as an HTTP string.
*
* The string representation of the Resonse is the same as the
* The string representation of the Response is the same as the
* one that will be sent to the client only if the prepare() method
* has been called before.
*
@@ -197,13 +198,15 @@ class Response
* the Request that is "associated" with this Response.
*
* @param Request $request A Request instance
*
* @return Response The current response.
*/
public function prepare(Request $request)
{
$headers = $this->headers;
if ($this->isInformational() || in_array($this->statusCode, array(204, 304))) {
$this->setContent('');
$this->setContent(null);
}
// Content-type based on the Request
@@ -231,11 +234,24 @@ class Response
if ('HEAD' === $request->getMethod()) {
// cf. RFC2616 14.13
$length = $headers->get('Content-Length');
$this->setContent('');
$this->setContent(null);
if ($length) {
$headers->set('Content-Length', $length);
}
}
// Fix protocol
if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) {
$this->setProtocolVersion('1.1');
}
// 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);
}
return $this;
}
/**
@@ -294,6 +310,18 @@ class Response
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
} elseif ('cli' !== PHP_SAPI) {
// 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;
$obStatus = ob_get_status(1);
while (($level = ob_get_level()) > 0 && $level !== $previous) {
$previous = $level;
if ($obStatus[$level - 1] && isset($obStatus[$level - 1]['del']) && $obStatus[$level - 1]['del']) {
ob_end_flush();
}
}
flush();
}
return $this;
@@ -365,7 +393,10 @@ class Response
* Sets the response status code.
*
* @param integer $code HTTP status code
* @param string $text HTTP status text
* @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.
*
* @return Response
*
@@ -375,12 +406,24 @@ class Response
*/
public function setStatusCode($code, $text = null)
{
$this->statusCode = (int) $code;
$this->statusCode = $code = (int) $code;
if ($this->isInvalid()) {
throw new \InvalidArgumentException(sprintf('The HTTP status code "%s" is not valid.', $code));
}
$this->statusText = false === $text ? '' : (null === $text ? self::$statusTexts[$this->statusCode] : $text);
if (null === $text) {
$this->statusText = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : '';
return $this;
}
if (false === $text) {
$this->statusText = '';
return $this;
}
$this->statusText = $text;
return $this;
}
@@ -528,7 +571,7 @@ class Response
*/
public function mustRevalidate()
{
return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('must-proxy-revalidate');
return $this->headers->hasCacheControlDirective('must-revalidate') || $this->headers->has('proxy-revalidate');
}
/**
@@ -542,7 +585,7 @@ class Response
*/
public function getDate()
{
return $this->headers->getDate('Date');
return $this->headers->getDate('Date', new \DateTime());
}
/**
@@ -701,7 +744,7 @@ class Response
* When the responses TTL is <= 0, the response may not be served from cache without first
* revalidating with the origin.
*
* @return integer The TTL in seconds
* @return integer|null The TTL in seconds
*
* @api
*/
@@ -960,6 +1003,10 @@ class Response
*/
public function isNotModified(Request $request)
{
if (!$request->isMethodSafe()) {
return false;
}
$lastModified = $request->headers->get('If-Modified-Since');
$notModified = false;
if ($etags = $request->getEtags()) {
@@ -1095,7 +1142,7 @@ class Response
*/
public function isRedirect($location = null)
{
return in_array($this->statusCode, array(201, 301, 302, 303, 307)) && (null === $location ?: $location == $this->headers->get('Location'));
return in_array($this->statusCode, array(201, 301, 302, 303, 307, 308)) && (null === $location ?: $location == $this->headers->get('Location'));
}
/**