Commit b97d20d9 authored by catch's avatar catch

Issue #2575847 by znerol: Remove request policy attribute from dynamic page cache subscriber

parent d87ade36
......@@ -40,14 +40,6 @@
*/
class DynamicPageCacheSubscriber implements EventSubscriberInterface {
/**
* Attribute name of the Dynamic Page Cache request policy result.
*
* @see onRouteMatch()
* @see onRespond()
*/
const ATTRIBUTE_REQUEST_POLICY_RESULT = '_dynamic_page_cache_request_policy_result';
/**
* Name of Dynamic Page Cache's response header.
*/
......@@ -103,6 +95,13 @@ class DynamicPageCacheSubscriber implements EventSubscriberInterface {
],
];
/**
* Internal cache of request policy results.
*
* @var \SplObjectStorage
*/
protected $requestPolicyResults;
/**
* Constructs a new DynamicPageCacheSubscriber object.
*
......@@ -120,6 +119,7 @@ public function __construct(RequestPolicyInterface $request_policy, ResponsePoli
$this->responsePolicy = $response_policy;
$this->renderCache = $render_cache;
$this->rendererConfig = $renderer_config;
$this->requestPolicyResults = new \SplObjectStorage();
}
/**
......@@ -134,7 +134,7 @@ public function onRouteMatch(GetResponseEvent $event) {
// does not have to redo the request policy check.
$request = $event->getRequest();
$request_policy_result = $this->requestPolicy->check($request);
$request->attributes->set(self::ATTRIBUTE_REQUEST_POLICY_RESULT, $request_policy_result);
$this->requestPolicyResults[$request] = $request_policy_result;
if ($request_policy_result === RequestPolicyInterface::DENY) {
return;
}
......@@ -189,14 +189,14 @@ public function onResponse(FilterResponseEvent $event) {
// @see \Drupal\Core\Routing\AccessAwareRouter::checkAccess()
// @see \Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber::on403()
$request = $event->getRequest();
if (!$request->attributes->has(self::ATTRIBUTE_REQUEST_POLICY_RESULT)) {
if (!isset($this->requestPolicyResults[$request])) {
return;
}
// Don't cache the response if the Dynamic Page Cache request & response
// policies are not met.
// @see onRouteMatch()
if ($request->attributes->get(self::ATTRIBUTE_REQUEST_POLICY_RESULT) === RequestPolicyInterface::DENY || $this->responsePolicy->check($response, $request) === ResponsePolicyInterface::DENY) {
if ($this->requestPolicyResults[$request] === RequestPolicyInterface::DENY || $this->responsePolicy->check($response, $request) === ResponsePolicyInterface::DENY) {
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment