upgraded dependencies
This commit is contained in:
133
vendor/symfony/http-foundation/Response.php
vendored
133
vendor/symfony/http-foundation/Response.php
vendored
@@ -67,11 +67,6 @@ class Response
|
||||
public const HTTP_UNPROCESSABLE_ENTITY = 422; // RFC4918
|
||||
public const HTTP_LOCKED = 423; // RFC4918
|
||||
public const HTTP_FAILED_DEPENDENCY = 424; // RFC4918
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public const HTTP_RESERVED_FOR_WEBDAV_ADVANCED_COLLECTIONS_EXPIRED_PROPOSAL = 425; // RFC2817
|
||||
public const HTTP_TOO_EARLY = 425; // RFC-ietf-httpbis-replay-04
|
||||
public const HTTP_UPGRADE_REQUIRED = 426; // RFC2817
|
||||
public const HTTP_PRECONDITION_REQUIRED = 428; // RFC6585
|
||||
@@ -90,6 +85,24 @@ class Response
|
||||
public const HTTP_NOT_EXTENDED = 510; // RFC2774
|
||||
public const HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511; // RFC6585
|
||||
|
||||
/**
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||
*/
|
||||
private const HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES = [
|
||||
'must_revalidate' => false,
|
||||
'no_cache' => false,
|
||||
'no_store' => false,
|
||||
'no_transform' => false,
|
||||
'public' => false,
|
||||
'private' => false,
|
||||
'proxy_revalidate' => false,
|
||||
'max_age' => true,
|
||||
's_maxage' => true,
|
||||
'immutable' => false,
|
||||
'last_modified' => true,
|
||||
'etag' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var ResponseHeaderBag
|
||||
*/
|
||||
@@ -125,7 +138,7 @@ class Response
|
||||
*
|
||||
* The list of codes is complete according to the
|
||||
* {@link https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml Hypertext Transfer Protocol (HTTP) Status Code Registry}
|
||||
* (last updated 2018-09-21).
|
||||
* (last updated 2021-10-01).
|
||||
*
|
||||
* Unless otherwise noted, the status code is defined in RFC2616.
|
||||
*
|
||||
@@ -167,14 +180,14 @@ class Response
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Payload Too Large',
|
||||
413 => 'Content Too Large', // RFC-ietf-httpbis-semantics
|
||||
414 => 'URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
418 => 'I\'m a teapot', // RFC2324
|
||||
421 => 'Misdirected Request', // RFC7540
|
||||
422 => 'Unprocessable Entity', // RFC4918
|
||||
422 => 'Unprocessable Content', // RFC-ietf-httpbis-semantics
|
||||
423 => 'Locked', // RFC4918
|
||||
424 => 'Failed Dependency', // RFC4918
|
||||
425 => 'Too Early', // RFC-ietf-httpbis-replay-04
|
||||
@@ -199,7 +212,7 @@ class Response
|
||||
/**
|
||||
* @throws \InvalidArgumentException When the HTTP status code is not valid
|
||||
*/
|
||||
public function __construct($content = '', int $status = 200, array $headers = [])
|
||||
public function __construct(?string $content = '', int $status = 200, array $headers = [])
|
||||
{
|
||||
$this->headers = new ResponseHeaderBag($headers);
|
||||
$this->setContent($content);
|
||||
@@ -215,14 +228,14 @@ class Response
|
||||
* return Response::create($body, 200)
|
||||
* ->setSharedMaxAge(300);
|
||||
*
|
||||
* @param mixed $content The response content, see setContent()
|
||||
* @param int $status The response status code
|
||||
* @param array $headers An array of response headers
|
||||
*
|
||||
* @return static
|
||||
*
|
||||
* @deprecated since Symfony 5.1, use __construct() instead.
|
||||
*/
|
||||
public static function create($content = '', $status = 200, $headers = [])
|
||||
public static function create(?string $content = '', int $status = 200, array $headers = [])
|
||||
{
|
||||
trigger_deprecation('symfony/http-foundation', '5.1', 'The "%s()" method is deprecated, use "new %s()" instead.', __METHOD__, static::class);
|
||||
|
||||
return new static($content, $status, $headers);
|
||||
}
|
||||
|
||||
@@ -233,7 +246,7 @@ class Response
|
||||
* 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
|
||||
* @return string
|
||||
*
|
||||
* @see prepare()
|
||||
*/
|
||||
@@ -382,6 +395,8 @@ class Response
|
||||
|
||||
if (\function_exists('fastcgi_finish_request')) {
|
||||
fastcgi_finish_request();
|
||||
} elseif (\function_exists('litespeed_finish_request')) {
|
||||
litespeed_finish_request();
|
||||
} elseif (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
|
||||
static::closeOutputBuffers(0, true);
|
||||
flush();
|
||||
@@ -393,21 +408,11 @@ class Response
|
||||
/**
|
||||
* Sets the response content.
|
||||
*
|
||||
* Valid types are strings, numbers, null, and objects that implement a __toString() method.
|
||||
*
|
||||
* @param mixed $content Content that can be cast to string
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
*/
|
||||
public function setContent($content)
|
||||
public function setContent(?string $content)
|
||||
{
|
||||
if (null !== $content && !\is_string($content) && !is_numeric($content) && !\is_callable([$content, '__toString'])) {
|
||||
throw new \UnexpectedValueException(sprintf('The Response content must be a string or object implementing __toString(), "%s" given.', \gettype($content)));
|
||||
}
|
||||
|
||||
$this->content = (string) $content;
|
||||
$this->content = $content ?? '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -429,7 +434,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setProtocolVersion(string $version)
|
||||
public function setProtocolVersion(string $version): object
|
||||
{
|
||||
$this->version = $version;
|
||||
|
||||
@@ -458,7 +463,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setStatusCode(int $code, $text = null)
|
||||
public function setStatusCode(int $code, string $text = null): object
|
||||
{
|
||||
$this->statusCode = $code;
|
||||
if ($this->isInvalid()) {
|
||||
@@ -499,7 +504,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setCharset(string $charset)
|
||||
public function setCharset(string $charset): object
|
||||
{
|
||||
$this->charset = $charset;
|
||||
|
||||
@@ -580,7 +585,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setPrivate()
|
||||
public function setPrivate(): object
|
||||
{
|
||||
$this->headers->removeCacheControlDirective('public');
|
||||
$this->headers->addCacheControlDirective('private');
|
||||
@@ -597,7 +602,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setPublic()
|
||||
public function setPublic(): object
|
||||
{
|
||||
$this->headers->addCacheControlDirective('public');
|
||||
$this->headers->removeCacheControlDirective('private');
|
||||
@@ -612,7 +617,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setImmutable(bool $immutable = true)
|
||||
public function setImmutable(bool $immutable = true): object
|
||||
{
|
||||
if ($immutable) {
|
||||
$this->headers->addCacheControlDirective('immutable');
|
||||
@@ -667,7 +672,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setDate(\DateTimeInterface $date)
|
||||
public function setDate(\DateTimeInterface $date): object
|
||||
{
|
||||
if ($date instanceof \DateTime) {
|
||||
$date = \DateTimeImmutable::createFromMutable($date);
|
||||
@@ -732,7 +737,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setExpires(\DateTimeInterface $date = null)
|
||||
public function setExpires(\DateTimeInterface $date = null): object
|
||||
{
|
||||
if (null === $date) {
|
||||
$this->headers->remove('Expires');
|
||||
@@ -785,7 +790,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setMaxAge(int $value)
|
||||
public function setMaxAge(int $value): object
|
||||
{
|
||||
$this->headers->addCacheControlDirective('max-age', $value);
|
||||
|
||||
@@ -801,7 +806,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setSharedMaxAge(int $value)
|
||||
public function setSharedMaxAge(int $value): object
|
||||
{
|
||||
$this->setPublic();
|
||||
$this->headers->addCacheControlDirective('s-maxage', $value);
|
||||
@@ -835,7 +840,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setTtl(int $seconds)
|
||||
public function setTtl(int $seconds): object
|
||||
{
|
||||
$this->setSharedMaxAge($this->getAge() + $seconds);
|
||||
|
||||
@@ -851,7 +856,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setClientTtl(int $seconds)
|
||||
public function setClientTtl(int $seconds): object
|
||||
{
|
||||
$this->setMaxAge($this->getAge() + $seconds);
|
||||
|
||||
@@ -879,7 +884,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setLastModified(\DateTimeInterface $date = null)
|
||||
public function setLastModified(\DateTimeInterface $date = null): object
|
||||
{
|
||||
if (null === $date) {
|
||||
$this->headers->remove('Last-Modified');
|
||||
@@ -917,7 +922,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setEtag(string $etag = null, bool $weak = false)
|
||||
public function setEtag(string $etag = null, bool $weak = false): object
|
||||
{
|
||||
if (null === $etag) {
|
||||
$this->headers->remove('Etag');
|
||||
@@ -935,7 +940,7 @@ class Response
|
||||
/**
|
||||
* Sets the response's cache headers (validation and/or expiration).
|
||||
*
|
||||
* Available options are: etag, last_modified, max_age, s_maxage, private, public and immutable.
|
||||
* Available options are: must_revalidate, no_cache, no_store, no_transform, public, private, proxy_revalidate, max_age, s_maxage, immutable, last_modified and etag.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
@@ -943,9 +948,9 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setCache(array $options)
|
||||
public function setCache(array $options): object
|
||||
{
|
||||
if ($diff = array_diff(array_keys($options), ['etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public', 'immutable'])) {
|
||||
if ($diff = array_diff(array_keys($options), array_keys(self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES))) {
|
||||
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', $diff)));
|
||||
}
|
||||
|
||||
@@ -965,6 +970,16 @@ class Response
|
||||
$this->setSharedMaxAge($options['s_maxage']);
|
||||
}
|
||||
|
||||
foreach (self::HTTP_RESPONSE_CACHE_CONTROL_DIRECTIVES as $directive => $hasValue) {
|
||||
if (!$hasValue && isset($options[$directive])) {
|
||||
if ($options[$directive]) {
|
||||
$this->headers->addCacheControlDirective(str_replace('_', '-', $directive));
|
||||
} else {
|
||||
$this->headers->removeCacheControlDirective(str_replace('_', '-', $directive));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['public'])) {
|
||||
if ($options['public']) {
|
||||
$this->setPublic();
|
||||
@@ -981,10 +996,6 @@ class Response
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['immutable'])) {
|
||||
$this->setImmutable((bool) $options['immutable']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -1000,7 +1011,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setNotModified()
|
||||
public function setNotModified(): object
|
||||
{
|
||||
$this->setStatusCode(304);
|
||||
$this->setContent(null);
|
||||
@@ -1036,10 +1047,10 @@ class Response
|
||||
|
||||
$ret = [];
|
||||
foreach ($vary as $item) {
|
||||
$ret = array_merge($ret, preg_split('/[\s,]+/', $item));
|
||||
$ret[] = preg_split('/[\s,]+/', $item);
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return array_merge([], ...$ret);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1052,7 +1063,7 @@ class Response
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function setVary($headers, bool $replace = true)
|
||||
public function setVary($headers, bool $replace = true): object
|
||||
{
|
||||
$this->headers->set('Vary', $headers, $replace);
|
||||
|
||||
@@ -1066,8 +1077,6 @@ class Response
|
||||
* If the Response is not modified, it sets the status code to 304 and
|
||||
* removes the actual content by calling the setNotModified() method.
|
||||
*
|
||||
* @return bool true if the Response validators match the Request, false otherwise
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
public function isNotModified(Request $request): bool
|
||||
@@ -1243,6 +1252,22 @@ class Response
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a response as safe according to RFC8674.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc8674
|
||||
*/
|
||||
public function setContentSafe(bool $safe = true): void
|
||||
{
|
||||
if ($safe) {
|
||||
$this->headers->set('Preference-Applied', 'safe');
|
||||
} elseif ('safe' === $this->headers->get('Preference-Applied')) {
|
||||
$this->headers->remove('Preference-Applied');
|
||||
}
|
||||
|
||||
$this->setVary('Prefer', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we need to remove Cache-Control for SSL encrypted downloads when using IE < 9.
|
||||
*
|
||||
|
Reference in New Issue
Block a user