- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Magento 2: Problem with plugin for Magento\Framework\App\Response\Http
i am trying to create a plugin for class Magento\Framework\App\Response\Http for beforeSendResponse and do some actions like session setter.. but it did not work as expected.
The code run several times after i cleared page cache. But after all, the code did not run any more. Even i write die(); in Magento\Framework\HTTP\PhpEnvironment\Response->sendReponse()(Magento\Framework\App\Response\Http extends this class) and nothing happend.
My code:
etc/frontend/di.xml
<type name="Magento\Framework\App\Response\Http"> <plugin name="setCookieForUser" type="Example\Module\Plugin\HttpSetCookie"/> </type>
Plugin/HttpSetCookie.php
namespace Example\Module\Plugin; class HttpSetCookie { public function beforeSendResponse( \Magento\Framework\App\Response\Http $subject ) { // do set cookie } }
i also configured varnish for my site. That is varnish problem? Can anyone please let me know why? How i solve this issue?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Magento 2: Problem with plugin for Magento\Framework\App\Response\Http
Clear the var/generation and try it out in Developer mode.
This Magento\Framework\App\Request\Http is the HTTP entry point in the pub/index.php Magento\Framework\App\Bootstrap class. So it might be possible that we couldn't use this in a plugin but worth giving it a try.
https://devdocs.magento.com/guides/v2.4/config-guide/bootstrap/magento-bootstrap.html
LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool