summaryrefslogtreecommitdiff
path: root/vendor/symfony/http-foundation/Response.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2018-05-31 09:45:16 +0100
committerGreg Roach <fisharebest@gmail.com>2018-05-31 09:57:27 +0100
commitffe6005c11fdad01969e67c039b0d73beb0232e9 (patch)
tree6d8df2e00473a813fef26155db549f9a969092f7 /vendor/symfony/http-foundation/Response.php
parentbba27599b02e0b6f90f62348bb4fa32bd74056d0 (diff)
downloadwebtrees-ffe6005c11fdad01969e67c039b0d73beb0232e9.tar.gz
webtrees-ffe6005c11fdad01969e67c039b0d73beb0232e9.tar.bz2
webtrees-ffe6005c11fdad01969e67c039b0d73beb0232e9.zip
Update minimum PHP version to 7.0.8 so that we can use the 3.4 LTS version of symfony
Diffstat (limited to 'vendor/symfony/http-foundation/Response.php')
-rw-r--r--vendor/symfony/http-foundation/Response.php102
1 files changed, 55 insertions, 47 deletions
diff --git a/vendor/symfony/http-foundation/Response.php b/vendor/symfony/http-foundation/Response.php
index 4af1e0bae2..e05194b018 100644
--- a/vendor/symfony/http-foundation/Response.php
+++ b/vendor/symfony/http-foundation/Response.php
@@ -21,6 +21,7 @@ class Response
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
+ const HTTP_EARLY_HINTS = 103; // RFC8297
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;
@@ -126,6 +127,7 @@ class Response
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing', // RFC2518
+ 103 => 'Early Hints',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
@@ -187,8 +189,6 @@ class Response
);
/**
- * Constructor.
- *
* @param mixed $content The response content, see setContent()
* @param int $status The response status code
* @param array $headers An array of response headers
@@ -201,11 +201,6 @@ class Response
$this->setContent($content);
$this->setStatusCode($status);
$this->setProtocolVersion('1.0');
-
- /* RFC2616 - 14.18 says all Responses need to have a Date */
- if (!$this->headers->has('Date')) {
- $this->setDate(\DateTime::createFromFormat('U', time()));
- }
}
/**
@@ -261,8 +256,6 @@ class Response
* 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
- *
* @return $this
*/
public function prepare(Request $request)
@@ -334,13 +327,8 @@ class Response
return $this;
}
- /* RFC2616 - 14.18 says all Responses need to have a Date */
- if (!$this->headers->has('Date')) {
- $this->setDate(\DateTime::createFromFormat('U', time()));
- }
-
// headers
- foreach ($this->headers->allPreserveCaseWithoutCookies() as $name => $values) {
+ foreach ($this->headers->allPreserveCase() as $name => $values) {
foreach ($values as $value) {
header($name.': '.$value, false, $this->statusCode);
}
@@ -349,15 +337,6 @@ class Response
// status
header(sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText), true, $this->statusCode);
- // cookies
- foreach ($this->headers->getCookies() as $cookie) {
- if ($cookie->isRaw()) {
- setrawcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
- } else {
- setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
- }
- }
-
return $this;
}
@@ -385,7 +364,7 @@ class Response
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
- } elseif ('cli' !== PHP_SAPI) {
+ } elseif (!\in_array(PHP_SAPI, array('cli', 'phpdbg'), true)) {
static::closeOutputBuffers(0, true);
}
@@ -455,12 +434,12 @@ class Response
/**
* Sets the response status code.
*
- * @param int $code HTTP status code
- * @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.
*
+ * @param int $code HTTP status code
+ * @param mixed $text HTTP status text
+ *
* @return $this
*
* @throws \InvalidArgumentException When the HTTP status code is not valid
@@ -532,13 +511,19 @@ class Response
}
/**
- * Returns true if the response is worth caching under any circumstance.
+ * Returns true if the response may safely be kept in a shared (surrogate) cache.
*
* 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.
+ * validator (Last-Modified, ETag) are considered uncacheable because there is
+ * no way to tell when or how to remove them from the cache.
+ *
+ * Note that RFC 7231 and RFC 7234 possibly allow for a more permissive implementation,
+ * for example "status codes that are defined as cacheable by default [...]
+ * can be reused by a cache with heuristic expiration unless otherwise indicated"
+ * (https://tools.ietf.org/html/rfc7231#section-6.1)
*
* @return bool true if the response is worth caching, false otherwise
*
@@ -621,6 +606,38 @@ class Response
}
/**
+ * Marks the response as "immutable".
+ *
+ * @param bool $immutable enables or disables the immutable directive
+ *
+ * @return $this
+ *
+ * @final
+ */
+ public function setImmutable($immutable = true)
+ {
+ if ($immutable) {
+ $this->headers->addCacheControlDirective('immutable');
+ } else {
+ $this->headers->removeCacheControlDirective('immutable');
+ }
+
+ return $this;
+ }
+
+ /**
+ * Returns true if the response is marked as "immutable".
+ *
+ * @return bool returns true if the response is marked as "immutable"; otherwise false
+ *
+ * @final
+ */
+ public function isImmutable()
+ {
+ return $this->headers->hasCacheControlDirective('immutable');
+ }
+
+ /**
* Returns true if the response must be revalidated by caches.
*
* This method indicates that the response must not be served stale by a
@@ -648,23 +665,12 @@ class Response
*/
public function getDate()
{
- /*
- RFC2616 - 14.18 says all Responses need to have a Date.
- Make sure we provide one even if it the header
- has been removed in the meantime.
- */
- if (!$this->headers->has('Date')) {
- $this->setDate(\DateTime::createFromFormat('U', time()));
- }
-
return $this->headers->getDate('Date');
}
/**
* Sets the Date header.
*
- * @param \DateTime $date A \DateTime instance
- *
* @return $this
*
* @final since version 3.2
@@ -944,7 +950,7 @@ class Response
/**
* Sets the response's cache headers (validation and/or expiration).
*
- * Available options are: etag, last_modified, max_age, s_maxage, private, and public.
+ * Available options are: etag, last_modified, max_age, s_maxage, private, public and immutable.
*
* @param array $options An array of cache options
*
@@ -956,7 +962,7 @@ class Response
*/
public function setCache(array $options)
{
- if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'))) {
+ if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public', 'immutable'))) {
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
}
@@ -992,6 +998,10 @@ class Response
}
}
+ if (isset($options['immutable'])) {
+ $this->setImmutable((bool) $options['immutable']);
+ }
+
return $this;
}
@@ -1077,8 +1087,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.
*
- * @param Request $request A Request instance
- *
* @return bool true if the Response validators match the Request, false otherwise
*
* @final since version 3.3
@@ -1261,7 +1269,7 @@ class Response
// PHP_OUTPUT_HANDLER_* are not defined on HHVM 3.3
$flags = defined('PHP_OUTPUT_HANDLER_REMOVABLE') ? PHP_OUTPUT_HANDLER_REMOVABLE | ($flush ? PHP_OUTPUT_HANDLER_FLUSHABLE : PHP_OUTPUT_HANDLER_CLEANABLE) : -1;
- while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || $flags === ($s['flags'] & $flags) : $s['del'])) {
+ while ($level-- > $targetLevel && ($s = $status[$level]) && (!isset($s['del']) ? !isset($s['flags']) || ($s['flags'] & $flags) === $flags : $s['del'])) {
if ($flush) {
ob_end_flush();
} else {
@@ -1279,7 +1287,7 @@ class Response
*/
protected function ensureIEOverSSLCompatibility(Request $request)
{
- if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) == 1 && true === $request->isSecure()) {
+ if (false !== stripos($this->headers->get('Content-Disposition'), 'attachment') && 1 == preg_match('/MSIE (.*?);/i', $request->server->get('HTTP_USER_AGENT'), $match) && true === $request->isSecure()) {
if ((int) preg_replace('/(MSIE )(.*?);/', '$2', $match[0]) < 9) {
$this->headers->remove('Cache-Control');
}