cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

`setJsonContent` should set header's Content-Type to application/json

Open liubin opened this issue 11 years ago • 8 comments

If I use $response->setJsonContent(array("status" => "OK"));, the header is:

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive
Content-Type:text/html; charset=UTF-8
Date:Tue, 10 Mar 2015 09:17:57 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:nginx/1.6.2
Transfer-Encoding:chunked
X-Powered-By:PHP/5.6.4

I think it should be set to application/json but not text/html.

Thanks

liubin avatar Mar 10 '15 09:03 liubin

Phalcon does not set this header automatically, you can set it as follows:

$response->setContentType("application/json");

andresgutierrez avatar Apr 07 '15 20:04 andresgutierrez

When you call method like 'setJsonContent' you'd expect it will also set the content type header field to "application/json" as well, by default.

stamster avatar Nov 05 '15 18:11 stamster

(Y)

stoiev avatar Nov 06 '15 08:11 stoiev

That's already implemented in Phalcon 2.1 https://github.com/phalcon/cphalcon/blob/2.1.x/phalcon/http/response.zep#L519

andresgutierrez avatar Nov 06 '15 14:11 andresgutierrez

it still does not work in Version => 3.2.0a

subdigger avatar Feb 28 '20 15:02 subdigger

@subdigger Looks like it's in for V4. https://github.com/phalcon/cphalcon/blob/master/phalcon/Http/Response.zep#L642

ruudboon avatar Feb 28 '20 17:02 ruudboon

@subdigger Looks like it's in for V4. https://github.com/phalcon/cphalcon/blob/master/phalcon/Http/Response.zep#L642

or not image

subdigger avatar Feb 28 '20 18:02 subdigger

@subdigger The example in there is not using setJsonContent The note says you need to set it manual OR use the Response object with setJsonContent

ruudboon avatar Feb 28 '20 18:02 ruudboon