diff --git a/vendor/magento/module-page-cache/Model/App/Response/HttpPlugin.php b/vendor/magento/module-page-cache/Model/App/Response/HttpPlugin.php index a6949cccc1ad..7de1eb459750 100644 --- a/vendor/magento/module-page-cache/Model/App/Response/HttpPlugin.php +++ b/vendor/magento/module-page-cache/Model/App/Response/HttpPlugin.php @@ -8,12 +8,24 @@ use Magento\Framework\App\PageCache\NotCacheableInterface; use Magento\Framework\App\Response\Http as HttpResponse; +use Magento\Framework\App\Request\Http as HttpRequest; +use Magento\Framework\App\Http\Context; /** * HTTP response plugin for frontend. */ class HttpPlugin { + /** + * @param Context $context + * @param HttpRequest $request + */ + public function __construct( + private Context $context, + private HttpRequest $request + ) { + } + /** * Set proper value of X-Magento-Vary cookie. * @@ -22,10 +34,19 @@ class HttpPlugin */ public function beforeSendResponse(HttpResponse $subject) { - if ($subject instanceof NotCacheableInterface || $subject->headersSent()) { + if ($subject instanceof NotCacheableInterface + || $subject->headersSent() + || $subject->getMetadata("NotCacheable") + ) { return; } + $currentVary = $this->context->getVaryString(); + $varyCookie = $this->request->get(HttpResponse::COOKIE_VARY_STRING); + if ($currentVary !== $varyCookie) { + //prevent caching with the old vary cookie + $subject->setNoCacheHeaders(); + } $subject->sendVary(); } }