Skip to content

Commit c18e36b

Browse files
committed
MAGETWO-86154: Wrong page cached for logged in user
1 parent 0d04ec6 commit c18e36b

File tree

1 file changed

+15
-2
lines changed
  • lib/internal/Magento/Framework/App/Response

1 file changed

+15
-2
lines changed

lib/internal/Magento/Framework/App/Response/Http.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
use Magento\Framework\App\Http\Context;
1111
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Stdlib\Cookie\CookieMetadata;
1213
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1314
use Magento\Framework\Stdlib\CookieManagerInterface;
1415
use Magento\Framework\Stdlib\DateTime;
1516
use Magento\Framework\App\Request\Http as HttpRequest;
17+
use Magento\Framework\Session\Config\ConfigInterface;
1618

1719
class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response
1820
{
@@ -50,25 +52,33 @@ class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response
5052
*/
5153
protected $dateTime;
5254

55+
/**
56+
* @var \Magento\Framework\Session\Config\ConfigInterface
57+
*/
58+
private $sessionConfig;
59+
5360
/**
5461
* @param HttpRequest $request
5562
* @param CookieManagerInterface $cookieManager
5663
* @param CookieMetadataFactory $cookieMetadataFactory
5764
* @param Context $context
5865
* @param DateTime $dateTime
66+
* @param ConfigInterface|null $sessionConfig
5967
*/
6068
public function __construct(
6169
HttpRequest $request,
6270
CookieManagerInterface $cookieManager,
6371
CookieMetadataFactory $cookieMetadataFactory,
6472
Context $context,
65-
DateTime $dateTime
73+
DateTime $dateTime,
74+
ConfigInterface $sessionConfig = null
6675
) {
6776
$this->request = $request;
6877
$this->cookieManager = $cookieManager;
6978
$this->cookieMetadataFactory = $cookieMetadataFactory;
7079
$this->context = $context;
7180
$this->dateTime = $dateTime;
81+
$this->sessionConfig = $sessionConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class);
7282
}
7383

7484
/**
@@ -91,7 +101,10 @@ public function sendVary()
91101
{
92102
$varyString = $this->context->getVaryString();
93103
if ($varyString) {
94-
$sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
104+
$cookieLifeTime = $this->sessionConfig->getCookieLifetime();
105+
$sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata(
106+
[CookieMetadata::KEY_DURATION => $cookieLifeTime]
107+
)->setPath('/');
95108
$this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $varyString, $sensitiveCookMetadata);
96109
} elseif ($this->request->get(self::COOKIE_VARY_STRING)) {
97110
$cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');

0 commit comments

Comments
 (0)