Hi all,
I am trying to setup a RESTful server in On-Rev. If the client is trying to perform an operation at a certain URL, and that operation is not allowed - ie., the client is trying to 'POST' information to a URL that only accepts 'GET' requests - then my response should contain a "405" status code + a list of the acceptable http methods at that URL. By default, however, the On-Rev server always issues "200 OK" status, if the script file is found and run.
I cannot find a way to change the http response code in On-Rev. Is this possible?
Can the HTTP Response Code Be Changed?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 37
- Joined: Thu Apr 19, 2012 8:12 am
Re: Can the HTTP Response Code Be Changed?
Worked it out on my own - posting what I found here, for future reference by others, and in case someone else may have a different solution.
In order to set the HTTP response's status code, before sending any output to the client, set a 'status' header, like this:
I have not tested it with LiveCode Server, but in On-Rev, setting the 'Status' header does not add a 'Status' header line, but instead makes the On-Rev server automatically output a properly formatted first-line for the response, like:
That's all there is to it!
In order to set the HTTP response's status code, before sending any output to the client, set a 'status' header, like this:
Code: Select all
put header "Status: 405 Method Not Allowed"
Code: Select all
HTTP/1.1 405 Method Not Allowed