cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2: Problem with plugin for Magento\Framework\App\Response\Http

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? 

1 REPLY 1

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

If issue solved, Click Kudos & Accept as Solution.
LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool