Can the HTTP Response Code Be Changed?

Are you using LiveCode to create server scripts or CGIs?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
igorBUSvRhc
Posts: 37
Joined: Thu Apr 19, 2012 8:12 am

Can the HTTP Response Code Be Changed?

Post by igorBUSvRhc » Sun May 06, 2012 11:25 am

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?

igorBUSvRhc
Posts: 37
Joined: Thu Apr 19, 2012 8:12 am

Re: Can the HTTP Response Code Be Changed?

Post by igorBUSvRhc » Tue May 08, 2012 1:54 am

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:

Code: Select all

put header "Status: 405 Method Not Allowed"
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:

Code: Select all

HTTP/1.1 405 Method Not Allowed
That's all there is to it!

Post Reply

Return to “CGIs and the Server”