cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Phalcon\Http\Response::setJsonContent does not set appropriate content type

Open thepatron opened this issue 11 years ago • 1 comments

Hello,

Could you please set the content type header to 'application/json' when using the Phalcon\Http\Response::setJsonContent() method? I feel like it is implied that if someone is setting the body of the response to JSON, the header should also be set appropriately. I feel the first snip below should equate to the second. Thanks in advance!

$returnObj = new \stdClass();
$returnObj->status = 'error';

$response = new \Phalcon\Http\Response();
$response->setJsonContent($returnObj);
$response->send();

vs:

$returnObj = new \stdClass();
$returnObj->status = 'error';

$response = new \Phalcon\Http\Response();
$response->setRawHeader("Content-Type: application/json; charset=utf-8");
$response->setContent(json_encode($returnObj));
$response->send();

thepatron avatar Sep 10 '15 16:09 thepatron

Implemented in 2.1.x

andresgutierrez avatar Sep 11 '15 12:09 andresgutierrez