HTTP headers do not change: yii2

I use yii2 and apache for my server. When I try to change the HTTP headers nothing changes.

Yii::$app->response->headers->set('Pragma', 'cache'); 

The default is Pragma: no-cache . This is both in my controller and in the configuration files. I tried suggesting to change the headers directly using

 headers("Pragma: cache"); 

This works fine, what could be the problem when using the Response class in Yii2?

+5
source share
2 answers

Before changing the header, you must set the format property in the response class.

in yii2 manual:

FORMAT_RAW: data will be processed as response content without any conversion. No additional HTTP header will be added .

http://www.yiiframework.com/doc-2.0/yii-web-response.html#$format-detail

example:

 Yii::$app->response->format = yii\web\Response::FORMAT_RAW; Yii::$app->response->headers->set('Pragma', 'cache'); 
+1
source

It seems that you have other code that changes the title (explicitly or implicitly). Checking the HeaderCollection class, I see no reason why it should not work. Therefore, check the code after the published line and make sure that it does not change the same header.

If you have not posted the appropriate code and provided a version of Yii2, this is the best I can do to help!

0
source

Source: https://habr.com/ru/post/1233632/


All Articles