I need to set my Content-Type header to "application/json; charset=utf-8" in Services responses.
I have tried drupal_add_http_header()
in my callback, in _services_request_postprocess_alter()
and in a custom ServicesFormatterInterface:
class ServicesJSON_UTF8Formatter implements ServicesFormatterInterface {
public function render($data) {
// json_encode doesn't give valid json with data that isn't an array/object.
if (is_scalar($data)) {
$data = array($data);
}
drupal_add_http_header('Content-Type', 'application/json; charset=utf-8');
return json_encode($data, JSON_UNESCAPED_UNICODE);
}
}
Sometimes the header gets set, and sometimes it comes back just "application/json" without my addition. Where can I set this to make certain my header makes it into the response?