mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-21 17:48:43 +02:00
⬆️ N°4770 Update to latest Symfony 3.4
This commit is contained in:
@@ -96,7 +96,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
|
||||
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
|
||||
|
||||
if (!$response->isSuccessful()) {
|
||||
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %s).', $subRequest->getUri(), $response->getStatusCode()));
|
||||
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));
|
||||
}
|
||||
|
||||
return $response->getContent();
|
||||
|
||||
@@ -80,13 +80,13 @@ class Esi extends AbstractSurrogate
|
||||
$content = preg_replace('#<esi\:remove>.*?</esi\:remove>#s', '', $content);
|
||||
$content = preg_replace('#<esi\:comment[^>]+>#s', '', $content);
|
||||
|
||||
$chunks = preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$chunks = preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', $content, -1, \PREG_SPLIT_DELIM_CAPTURE);
|
||||
$chunks[0] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[0]);
|
||||
|
||||
$i = 1;
|
||||
while (isset($chunks[$i])) {
|
||||
$options = [];
|
||||
preg_match_all('/(src|onerror|alt)="([^"]*?)"/', $chunks[$i], $matches, PREG_SET_ORDER);
|
||||
preg_match_all('/(src|onerror|alt)="([^"]*?)"/', $chunks[$i], $matches, \PREG_SET_ORDER);
|
||||
foreach ($matches as $set) {
|
||||
$options[$set[1]] = $set[2];
|
||||
}
|
||||
|
||||
@@ -323,6 +323,10 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
return $this->validate($request, $entry, $catch);
|
||||
}
|
||||
|
||||
if ($entry->headers->hasCacheControlDirective('no-cache')) {
|
||||
return $this->validate($request, $entry, $catch);
|
||||
}
|
||||
|
||||
$this->record($request, 'fresh');
|
||||
|
||||
$entry->headers->set('Age', $entry->getAge());
|
||||
@@ -448,13 +452,37 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
// always a "master" request (as the real master request can be in cache)
|
||||
$response = SubRequestHandler::handle($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $catch);
|
||||
|
||||
// we don't implement the stale-if-error on Requests, which is nonetheless part of the RFC
|
||||
if (null !== $entry && \in_array($response->getStatusCode(), [500, 502, 503, 504])) {
|
||||
/*
|
||||
* Support stale-if-error given on Responses or as a config option.
|
||||
* RFC 7234 summarizes in Section 4.2.4 (but also mentions with the individual
|
||||
* Cache-Control directives) that
|
||||
*
|
||||
* A cache MUST NOT generate a stale response if it is prohibited by an
|
||||
* explicit in-protocol directive (e.g., by a "no-store" or "no-cache"
|
||||
* cache directive, a "must-revalidate" cache-response-directive, or an
|
||||
* applicable "s-maxage" or "proxy-revalidate" cache-response-directive;
|
||||
* see Section 5.2.2).
|
||||
*
|
||||
* https://tools.ietf.org/html/rfc7234#section-4.2.4
|
||||
*
|
||||
* We deviate from this in one detail, namely that we *do* serve entries in the
|
||||
* stale-if-error case even if they have a `s-maxage` Cache-Control directive.
|
||||
*/
|
||||
if (null !== $entry
|
||||
&& \in_array($response->getStatusCode(), [500, 502, 503, 504])
|
||||
&& !$entry->headers->hasCacheControlDirective('no-cache')
|
||||
&& !$entry->mustRevalidate()
|
||||
) {
|
||||
if (null === $age = $entry->headers->getCacheControlDirective('stale-if-error')) {
|
||||
$age = $this->options['stale_if_error'];
|
||||
}
|
||||
|
||||
if (abs($entry->getTtl()) < $age) {
|
||||
/*
|
||||
* stale-if-error gives the (extra) time that the Response may be used *after* it has become stale.
|
||||
* So we compare the time the $entry has been sitting in the cache already with the
|
||||
* time it was fresh plus the allowed grace period.
|
||||
*/
|
||||
if ($entry->getAge() <= $entry->getMaxAge() + $age) {
|
||||
$this->record($request, 'stale-if-error');
|
||||
|
||||
return $entry;
|
||||
|
||||
@@ -110,8 +110,6 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface
|
||||
$response->headers->set('Age', $this->age);
|
||||
|
||||
if ($this->isNotCacheableResponseEmbedded) {
|
||||
$response->setExpires($response->getDate());
|
||||
|
||||
if ($this->flagDirectives['no-store']) {
|
||||
$response->headers->set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
} else {
|
||||
|
||||
@@ -65,13 +65,13 @@ class Ssi extends AbstractSurrogate
|
||||
// we don't use a proper XML parser here as we can have SSI tags in a plain text response
|
||||
$content = $response->getContent();
|
||||
|
||||
$chunks = preg_split('#<!--\#include\s+(.*?)\s*-->#', $content, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$chunks = preg_split('#<!--\#include\s+(.*?)\s*-->#', $content, -1, \PREG_SPLIT_DELIM_CAPTURE);
|
||||
$chunks[0] = str_replace($this->phpEscapeMap[0], $this->phpEscapeMap[1], $chunks[0]);
|
||||
|
||||
$i = 1;
|
||||
while (isset($chunks[$i])) {
|
||||
$options = [];
|
||||
preg_match_all('/(virtual)="([^"]*?)"/', $chunks[$i], $matches, PREG_SET_ORDER);
|
||||
preg_match_all('/(virtual)="([^"]*?)"/', $chunks[$i], $matches, \PREG_SET_ORDER);
|
||||
foreach ($matches as $set) {
|
||||
$options[$set[1]] = $set[2];
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class Store implements StoreInterface
|
||||
{
|
||||
// unlock everything
|
||||
foreach ($this->locks as $lock) {
|
||||
flock($lock, LOCK_UN);
|
||||
flock($lock, \LOCK_UN);
|
||||
fclose($lock);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class Store implements StoreInterface
|
||||
return $path;
|
||||
}
|
||||
$h = fopen($path, 'cb');
|
||||
if (!flock($h, LOCK_EX | LOCK_NB)) {
|
||||
if (!flock($h, \LOCK_EX | \LOCK_NB)) {
|
||||
fclose($h);
|
||||
|
||||
return $path;
|
||||
@@ -94,7 +94,7 @@ class Store implements StoreInterface
|
||||
$key = $this->getCacheKey($request);
|
||||
|
||||
if (isset($this->locks[$key])) {
|
||||
flock($this->locks[$key], LOCK_UN);
|
||||
flock($this->locks[$key], \LOCK_UN);
|
||||
fclose($this->locks[$key]);
|
||||
unset($this->locks[$key]);
|
||||
|
||||
@@ -117,8 +117,8 @@ class Store implements StoreInterface
|
||||
}
|
||||
|
||||
$h = fopen($path, 'rb');
|
||||
flock($h, LOCK_EX | LOCK_NB, $wouldBlock);
|
||||
flock($h, LOCK_UN); // release the lock we just acquired
|
||||
flock($h, \LOCK_EX | \LOCK_NB, $wouldBlock);
|
||||
flock($h, \LOCK_UN); // release the lock we just acquired
|
||||
fclose($h);
|
||||
|
||||
return (bool) $wouldBlock;
|
||||
@@ -152,8 +152,8 @@ class Store implements StoreInterface
|
||||
}
|
||||
|
||||
$headers = $match[1];
|
||||
if (file_exists($body = $this->getPath($headers['x-content-digest'][0]))) {
|
||||
return $this->restoreResponse($headers, $body);
|
||||
if (file_exists($path = $this->getPath($headers['x-content-digest'][0]))) {
|
||||
return $this->restoreResponse($headers, $path);
|
||||
}
|
||||
|
||||
// TODO the metaStore referenced an entity that doesn't exist in
|
||||
@@ -177,16 +177,25 @@ class Store implements StoreInterface
|
||||
$key = $this->getCacheKey($request);
|
||||
$storedEnv = $this->persistRequest($request);
|
||||
|
||||
// write the response body to the entity store if this is the original response
|
||||
if (!$response->headers->has('X-Content-Digest')) {
|
||||
$digest = $this->generateContentDigest($response);
|
||||
|
||||
if (!$this->save($digest, $response->getContent())) {
|
||||
throw new \RuntimeException('Unable to store the entity.');
|
||||
if ($response->headers->has('X-Body-File')) {
|
||||
// Assume the response came from disk, but at least perform some safeguard checks
|
||||
if (!$response->headers->has('X-Content-Digest')) {
|
||||
throw new \RuntimeException('A restored response must have the X-Content-Digest header.');
|
||||
}
|
||||
|
||||
$digest = $response->headers->get('X-Content-Digest');
|
||||
if ($this->getPath($digest) !== $response->headers->get('X-Body-File')) {
|
||||
throw new \RuntimeException('X-Body-File and X-Content-Digest do not match.');
|
||||
}
|
||||
// Everything seems ok, omit writing content to disk
|
||||
} else {
|
||||
$digest = $this->generateContentDigest($response);
|
||||
$response->headers->set('X-Content-Digest', $digest);
|
||||
|
||||
if (!$this->save($digest, $response->getContent(), false)) {
|
||||
throw new \RuntimeException('Unable to store the entity.');
|
||||
}
|
||||
|
||||
if (!$response->headers->has('Transfer-Encoding')) {
|
||||
$response->headers->set('Content-Length', \strlen($response->getContent()));
|
||||
}
|
||||
@@ -331,7 +340,7 @@ class Store implements StoreInterface
|
||||
{
|
||||
$key = $this->getCacheKey(Request::create($url));
|
||||
if (isset($this->locks[$key])) {
|
||||
flock($this->locks[$key], LOCK_UN);
|
||||
flock($this->locks[$key], \LOCK_UN);
|
||||
fclose($this->locks[$key]);
|
||||
unset($this->locks[$key]);
|
||||
}
|
||||
@@ -362,15 +371,20 @@ class Store implements StoreInterface
|
||||
/**
|
||||
* Save data for the given key.
|
||||
*
|
||||
* @param string $key The store key
|
||||
* @param string $data The data to store
|
||||
* @param string $key The store key
|
||||
* @param string $data The data to store
|
||||
* @param bool $overwrite Whether existing data should be overwritten
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function save($key, $data)
|
||||
private function save($key, $data, $overwrite = true)
|
||||
{
|
||||
$path = $this->getPath($key);
|
||||
|
||||
if (!$overwrite && file_exists($path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isset($this->locks[$key])) {
|
||||
$fp = $this->locks[$key];
|
||||
@ftruncate($fp, 0);
|
||||
@@ -476,19 +490,19 @@ class Store implements StoreInterface
|
||||
* Restores a Response from the HTTP headers and body.
|
||||
*
|
||||
* @param array $headers An array of HTTP headers for the Response
|
||||
* @param string $body The Response body
|
||||
* @param string $path Path to the Response body
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
private function restoreResponse($headers, $body = null)
|
||||
private function restoreResponse($headers, $path = null)
|
||||
{
|
||||
$status = $headers['X-Status'][0];
|
||||
unset($headers['X-Status']);
|
||||
|
||||
if (null !== $body) {
|
||||
$headers['X-Body-File'] = [$body];
|
||||
if (null !== $path) {
|
||||
$headers['X-Body-File'] = [$path];
|
||||
}
|
||||
|
||||
return new Response($body, $status, $headers);
|
||||
return new Response($path, $status, $headers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user