Welcome Guest, Not a member yet? Register   Sign In
Error responses change mime type to text/html
#1

The web service we've developed in CodeIgniter has some error conditions where, instead of returning an HTTP status code of 200, we return a code of (for example) 403.  

Our system usually delivers JSON, so we are expecting a response from the server in JSON even when the HTTP code is not 200.

However, even though the mime type is explicitly set to application/json, we are receiving a mime type of text/html in this instance (and all instances where there is an HTTP error code return).

What seems to be happening is that the output is using

Code:
echo($output)

when the status code is 200 and

Code:
exit($output)

when the status code is something else.

Is it possible that using exit in this way will change CodeIgniter's HTTP header information (specifically the mime type)?

The content body is still JSON, as expected.
Reply
#2

You have to tell the output class what content-type to use.
Reply
#3

(12-09-2014, 04:26 AM)Narf Wrote: You have to tell the output class what content-type to use.

Yes, we do that.  Outputting its value immediately before the exit command shows that it is set correctly.  But still the actual header is set to text/html instead of application/json.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB