I am using yii2 and apache for my server. When I try to change HTTP headers, nothing changes.
Yii::$app->response->headers->set('Pragma', 'cache');
The default Pragma: no-cache
remains. This is both on my controller or configuration files. I have tried a suggestion to change headers directly using
headers("Pragma: cache");
This works perfectly, what might be the issue when using Response class in Yii2?
you must before changing header, set format
property in response class.
in yii2 manual :
FORMAT_RAW: the data will be treated as the response content without any conversion. No extra 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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With