diff --git a/core/modules/image/image.services.yml b/core/modules/image/image.services.yml index dee37f2..7f1f985 100644 --- a/core/modules/image/image.services.yml +++ b/core/modules/image/image.services.yml @@ -6,7 +6,8 @@ services: plugin.manager.image.effect: class: Drupal\image\ImageEffectManager parent: default_plugin_manager - image.page_cache_request_policy.image_path: - class: Drupal\image\PageCache\IsPrivateImageStyleDownloadPath + image.page_cache_request_policy.deny_private_image_style_download: + class: Drupal\image\PageCache\DenyPrivateImageStyleDownload + arguments: ['@current_route_match'] tags: - - { name: page_cache_request_policy } + - { name: page_cache_response_policy } diff --git a/core/modules/image/src/PageCache/DenyPrivateImageStyleDownload.php b/core/modules/image/src/PageCache/DenyPrivateImageStyleDownload.php new file mode 100644 index 0000000..8beba08 --- /dev/null +++ b/core/modules/image/src/PageCache/DenyPrivateImageStyleDownload.php @@ -0,0 +1,49 @@ +routeMatch = $route_match; + } + + /** + * Test whether this request goes to /image/preview. + */ + public function check(Response $response, Request $request) { + if ($this->routeMatch->getRouteName() === 'image.style_private') { + return static::DENY; + } + } + +} diff --git a/core/modules/image/src/PageCache/IsPrivateImageStyleDownloadPath.php b/core/modules/image/src/PageCache/IsPrivateImageStyleDownloadPath.php deleted file mode 100644 index d78bd21..0000000 --- a/core/modules/image/src/PageCache/IsPrivateImageStyleDownloadPath.php +++ /dev/null @@ -1,30 +0,0 @@ -getPathInfo(), '/system/files/styles/') === 0) { - return RequestPolicyInterface::DENY; - } - } - -} diff --git a/core/modules/node/node.services.yml b/core/modules/node/node.services.yml index 8111819..68f0af1 100644 --- a/core/modules/node/node.services.yml +++ b/core/modules/node/node.services.yml @@ -34,7 +34,8 @@ services: arguments: ['@user.tempstore'] tags: - { name: paramconverter } - node.page_cache_request_policy.node_preview_path: - class: Drupal\node\PageCache\IsPreviewPath + node.page_cache_request_policy.deny_node_preview: + class: Drupal\node\PageCache\DenyNodePreview + arguments: ['@current_route_match'] tags: - - { name: page_cache_request_policy } + - { name: page_cache_response_policy } diff --git a/core/modules/node/src/PageCache/DenyNodePreview.php b/core/modules/node/src/PageCache/DenyNodePreview.php new file mode 100644 index 0000000..0f78018 --- /dev/null +++ b/core/modules/node/src/PageCache/DenyNodePreview.php @@ -0,0 +1,49 @@ +routeMatch = $route_match; + } + + /** + * Test whether this request goes to /node/preview. + */ + public function check(Response $response, Request $request) { + if ($this->routeMatch->getRouteName() === 'entity.node.preview') { + return static::DENY; + } + } + +} diff --git a/core/modules/node/src/PageCache/IsPreviewPath.php b/core/modules/node/src/PageCache/IsPreviewPath.php deleted file mode 100644 index f5b84a4..0000000 --- a/core/modules/node/src/PageCache/IsPreviewPath.php +++ /dev/null @@ -1,30 +0,0 @@ -getPathInfo(), '/node/preview/') === 0) { - return RequestPolicyInterface::DENY; - } - } - -} diff --git a/core/modules/toolbar/src/PageCache/AllowToolbarPath.php b/core/modules/toolbar/src/PageCache/AllowToolbarPath.php new file mode 100644 index 0000000..bb331af --- /dev/null +++ b/core/modules/toolbar/src/PageCache/AllowToolbarPath.php @@ -0,0 +1,37 @@ +getPathInfo(); + $toolbar_path_offset = strpos($path, '/toolbar/subtrees/'); + if ($toolbar_path_offset !== FALSE) { + // Also accept paths matching at the first slash in order to cater for + // sites using language prefixes. + $second_slash = strpos($path, '/', 1); + if ($toolbar_path_offset === 0 || $toolbar_path_offset === $second_slash) { + return static::ALLOW; + } + } + } + +} diff --git a/core/modules/toolbar/src/PageCache/IsToolbarPath.php b/core/modules/toolbar/src/PageCache/IsToolbarPath.php deleted file mode 100644 index aa48138..0000000 --- a/core/modules/toolbar/src/PageCache/IsToolbarPath.php +++ /dev/null @@ -1,30 +0,0 @@ -getPathInfo(), '/toolbar/subtrees/') === 0) { - return RequestPolicyInterface::ALLOW; - } - } - -} diff --git a/core/modules/toolbar/toolbar.services.yml b/core/modules/toolbar/toolbar.services.yml index c0eea8b..278d3c7 100644 --- a/core/modules/toolbar/toolbar.services.yml +++ b/core/modules/toolbar/toolbar.services.yml @@ -6,7 +6,7 @@ services: factory_method: get factory_service: cache_factory arguments: [toolbar] - toolbar.page_cache_request_policy.toolbar_path: - class: Drupal\toolbar\PageCache\IsToolbarPath + toolbar.page_cache_request_policy.allow_toolbar_path: + class: Drupal\toolbar\PageCache\AllowToolbarPath tags: - { name: page_cache_request_policy }