violet-php / streaming-json-encoder

PHP library for iteratively encoding large JSON documents piece by piece
http://violet.riimu.net
MIT License
315 stars 16 forks source link

Content-Type is text/html; charset=UTF-8 #2

Closed boonstoppel closed 6 years ago

boonstoppel commented 6 years ago

The content type in the HTTP Header is always "Content-Type: text/html; charset=UTF-8".

For JSON this should be "Content-Type: application/json; charset=UTF-8"

Setting the header manually did not work.

Riimu commented 6 years ago

This library does not change or touch the headers sent by the script in any way. You will have to do that yourself, as that depends widely on what kind of framework you are using.

In simplest cases, it should be enough to just use the following to set the header before outputting any json:

header('Content-Type: application/json; charset=utf-8');

However, if that does not work for you, perhaps you are overriding this header somewhere or it is overridden by whatever server architecture you are using.

Either way, settings the headers is essentially out of the scope of this library.