Cphalcon: Response setHeaders overwrites setContentType

Created on 6 May 2017  路  3Comments  路  Source: phalcon/cphalcon

Reponse setHeaders is scrubbing setContentType.

Expected and Actual Behavior

Expected:
I expected the reponse->setHeaders to merge with what was already in headers.

Actual :
I had response->setContentType('application/json') before response->setHeaders. The result meant I was losing the desired content type and it was reverting back to text/html.

Working:

$this->response->setHeaders($headers);
$this->response->setContentType('application/json', 'UTF-8');

Not working:

$this->response->setContentType('application/json', 'UTF-8');
$this->response->setHeaders($headers);

Details

  • Phalcon version: 3.1.2
  • PHP Version: 7.0.18
  • Operating System: Windows running a Doker environment for development.
  • Installation type: Docker box.
  • Zephir version (if any):
  • Server: Nginx
bug low

Most helpful comment

I recommend that this be added to the Phalcon 4 milestone with merging on by default. If it is added in Phalcon 3 then merging will need to be off by default. It can be currently worked around by extending the Response class and calling getHeaders in setHeaders.

All 3 comments

I recommend that this be added to the Phalcon 4 milestone with merging on by default. If it is added in Phalcon 3 then merging will need to be off by default. It can be currently worked around by extending the Response class and calling getHeaders in setHeaders.

@linxlad

Well not sure what you exactly do further but $this->response->setContentType('application/json', 'UTF-8'); is most likely not needed just do:

$model = $model->toArray();
return $this->request->setJsonContent($model);

Addressed in https://github.com/phalcon/cphalcon/pull/13669

Thank you @linxlad

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hesalx picture hesalx  路  4Comments

masood09 picture masood09  路  4Comments

Yakovlev-Melarn picture Yakovlev-Melarn  路  3Comments

hailie-rei picture hailie-rei  路  3Comments

abcpremium picture abcpremium  路  3Comments