webmcp
annotate framework/env/request/set_status.lua @ 518:02d505b6090c
Added section about global variables and the environment to WebMCP's documentation
| author | jbe | 
|---|---|
| date | Mon Aug 21 14:50:27 2017 +0200 (2017-08-21) | 
| parents | 9fdfb27f8e67 | 
| children | 
| rev | line source | 
|---|---|
| jbe/bsw@0 | 1 --[[-- | 
| jbe/bsw@0 | 2 request.set_status( | 
| jbe/bsw@0 | 3 str -- string containing a HTTP status code, e.g. "404 Not Found" | 
| jbe/bsw@0 | 4 ) | 
| jbe/bsw@0 | 5 | 
| jbe/bsw@0 | 6 Calling this function causes a HTTP status different from 200 OK (or in case of error different from 500 Internal Server Error) to be sent to the browser. | 
| jbe/bsw@0 | 7 | 
| jbe/bsw@0 | 8 --]]-- | 
| jbe/bsw@0 | 9 | 
| jbe/bsw@0 | 10 function request.set_status(str) | 
| jbe/bsw@0 | 11 if str then | 
| jbe/bsw@0 | 12 local t = type(str) | 
| jbe/bsw@0 | 13 if type(str) == "number" then | 
| jbe/bsw@0 | 14 str = tostring(str) | 
| jbe/bsw@0 | 15 elseif type(str) ~= "string" then | 
| jbe/bsw@0 | 16 error("request.set_status(...) must be called with a string as parameter.") | 
| jbe/bsw@0 | 17 end | 
| jbe/bsw@0 | 18 request._status = str | 
| jbe/bsw@0 | 19 else | 
| jbe/bsw@0 | 20 request._status = nil | 
| jbe/bsw@0 | 21 end | 
| jbe/bsw@0 | 22 end |