Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP headers are not being changed: yii2

Tags:

php

yii2

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?

like image 685
learner Avatar asked Oct 13 '15 15:10

learner


1 Answers

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');
like image 60
Think Big Avatar answered Oct 04 '22 12:10

Think Big