update patch 1
This commit is contained in:
@@ -46,13 +46,13 @@ abstract class AbstractSurrogate implements SurrogateInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
return str_contains($value, sprintf('%s/1.0', strtoupper($this->getName())));
|
||||
return str_contains($value, \sprintf('%s/1.0', strtoupper($this->getName())));
|
||||
}
|
||||
|
||||
public function addSurrogateCapability(Request $request): void
|
||||
{
|
||||
$current = $request->headers->get('Surrogate-Capability');
|
||||
$new = sprintf('symfony="%s/1.0"', strtoupper($this->getName()));
|
||||
$new = \sprintf('symfony="%s/1.0"', strtoupper($this->getName()));
|
||||
|
||||
$request->headers->set('Surrogate-Capability', $current ? $current.', '.$new : $new);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
$pattern = sprintf('#content="[^"]*%s/1.0[^"]*"#', strtoupper($this->getName()));
|
||||
$pattern = \sprintf('#content="[^"]*%s/1.0[^"]*"#', strtoupper($this->getName()));
|
||||
|
||||
return (bool) preg_match($pattern, $control);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ abstract class AbstractSurrogate implements SurrogateInterface
|
||||
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
|
||||
|
||||
if (!$response->isSuccessful() && Response::HTTP_NOT_MODIFIED !== $response->getStatusCode()) {
|
||||
throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));
|
||||
throw new \RuntimeException(\sprintf('Error when rendering "%s" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));
|
||||
}
|
||||
|
||||
return $response->getContent();
|
||||
@@ -105,12 +105,12 @@ abstract class AbstractSurrogate implements SurrogateInterface
|
||||
$value = $response->headers->get('Surrogate-Control');
|
||||
$upperName = strtoupper($this->getName());
|
||||
|
||||
if (sprintf('content="%s/1.0"', $upperName) == $value) {
|
||||
if (\sprintf('content="%s/1.0"', $upperName) == $value) {
|
||||
$response->headers->remove('Surrogate-Control');
|
||||
} elseif (preg_match(sprintf('#,\s*content="%s/1.0"#', $upperName), $value)) {
|
||||
$response->headers->set('Surrogate-Control', preg_replace(sprintf('#,\s*content="%s/1.0"#', $upperName), '', $value));
|
||||
} elseif (preg_match(sprintf('#content="%s/1.0",\s*#', $upperName), $value)) {
|
||||
$response->headers->set('Surrogate-Control', preg_replace(sprintf('#content="%s/1.0",\s*#', $upperName), '', $value));
|
||||
} elseif (preg_match(\sprintf('#,\s*content="%s/1.0"#', $upperName), $value)) {
|
||||
$response->headers->set('Surrogate-Control', preg_replace(\sprintf('#,\s*content="%s/1.0"#', $upperName), '', $value));
|
||||
} elseif (preg_match(\sprintf('#content="%s/1.0",\s*#', $upperName), $value)) {
|
||||
$response->headers->set('Surrogate-Control', preg_replace(\sprintf('#content="%s/1.0",\s*#', $upperName), '', $value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -41,14 +41,14 @@ class Esi extends AbstractSurrogate
|
||||
|
||||
public function renderIncludeTag(string $uri, ?string $alt = null, bool $ignoreErrors = true, string $comment = ''): string
|
||||
{
|
||||
$html = sprintf('<esi:include src="%s"%s%s />',
|
||||
$html = \sprintf('<esi:include src="%s"%s%s />',
|
||||
$uri,
|
||||
$ignoreErrors ? ' onerror="continue"' : '',
|
||||
$alt ? sprintf(' alt="%s"', $alt) : ''
|
||||
$alt ? \sprintf(' alt="%s"', $alt) : ''
|
||||
);
|
||||
|
||||
if ($comment) {
|
||||
return sprintf("<esi:comment text=\"%s\" />\n%s", $comment, $html);
|
||||
return \sprintf("<esi:comment text=\"%s\" />\n%s", $comment, $html);
|
||||
}
|
||||
|
||||
return $html;
|
||||
|
||||
+7
-3
@@ -17,6 +17,7 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\HttpCache;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
@@ -87,7 +88,6 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
private ?SurrogateInterface $surrogate = null,
|
||||
array $options = [],
|
||||
) {
|
||||
|
||||
// needed in case there is a fatal error because the backend is too slow to respond
|
||||
register_shutdown_function($this->store->cleanup(...));
|
||||
|
||||
@@ -149,7 +149,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
{
|
||||
$log = [];
|
||||
foreach ($this->traces as $request => $traces) {
|
||||
$log[] = sprintf('%s: %s', $request, implode(', ', $traces));
|
||||
$log[] = \sprintf('%s: %s', $request, implode(', ', $traces));
|
||||
}
|
||||
|
||||
return implode('; ', $log);
|
||||
@@ -705,7 +705,11 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
$path .= '?'.$qs;
|
||||
}
|
||||
|
||||
return $request->getMethod().' '.$path;
|
||||
try {
|
||||
return $request->getMethod().' '.$path;
|
||||
} catch (SuspiciousOperationException) {
|
||||
return '_BAD_METHOD_ '.$path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class Ssi extends AbstractSurrogate
|
||||
|
||||
public function renderIncludeTag(string $uri, ?string $alt = null, bool $ignoreErrors = true, string $comment = ''): string
|
||||
{
|
||||
return sprintf('<!--#include virtual="%s" -->', $uri);
|
||||
return \sprintf('<!--#include virtual="%s" -->', $uri);
|
||||
}
|
||||
|
||||
public function process(Request $request, Response $response): Response
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class Store implements StoreInterface
|
||||
private array $options = [],
|
||||
) {
|
||||
if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) {
|
||||
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
|
||||
throw new \RuntimeException(\sprintf('Unable to create the store directory (%s).', $this->root));
|
||||
}
|
||||
$this->keyCache = new \SplObjectStorage();
|
||||
$this->options['private_headers'] ??= ['Set-Cookie'];
|
||||
|
||||
@@ -51,16 +51,16 @@ class SubRequestHandler
|
||||
$trustedValues = [];
|
||||
foreach (array_reverse($request->getClientIps()) as $ip) {
|
||||
$trustedIps[] = $ip;
|
||||
$trustedValues[] = sprintf('for="%s"', $ip);
|
||||
$trustedValues[] = \sprintf('for="%s"', $ip);
|
||||
}
|
||||
if ($ip !== $remoteAddr) {
|
||||
$trustedIps[] = $remoteAddr;
|
||||
$trustedValues[] = sprintf('for="%s"', $remoteAddr);
|
||||
$trustedValues[] = \sprintf('for="%s"', $remoteAddr);
|
||||
}
|
||||
|
||||
// set trusted values, reusing as much as possible the global trusted settings
|
||||
if (Request::HEADER_FORWARDED & $trustedHeaderSet) {
|
||||
$trustedValues[0] .= sprintf(';host="%s";proto=%s', $request->getHttpHost(), $request->getScheme());
|
||||
$trustedValues[0] .= \sprintf(';host="%s";proto=%s', $request->getHttpHost(), $request->getScheme());
|
||||
$request->headers->set('Forwarded', $v = implode(', ', $trustedValues));
|
||||
$request->server->set('HTTP_FORWARDED', $v);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user