I’m writing a RESTful webservice that returns custom/existing HTTP headers on successful/unsuccessful operations.
For eg., if the authentication fails, the 401 HTTP header will be sent, etc.
I’ve sent the headers via the PHP header() function, but of course that is not sent back to the caller. What I really need to do is to send headers via Apache, instead of PHP, back to the calling script. I’m carrying out certain checks for the data that I receive in my webservice, and then sending the headers. How would I go about pushing these headers via Apache instead?
Thanks!
Figured out the solution. Pass in ‘true’ as the second argument to header(), and the actual status code as the third argument. For eg., header(‘HTTP 1.1/400 Bad Request’, true, 400). This will force the 400 status code to the caller. I’ve checked this atleast in LiveHTTPHeaders, so it might work. I’ll just need to call this via curl to be completely sure.