-
-
Save erdoukki/f1c006692f572727f40162886c3e81e3 to your computer and use it in GitHub Desktop.
An example of a Lua script being run under Apache mod_lua. From http://httpd.apache.org/docs/current/mod/mod_lua.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "string" | |
--[[ | |
http://httpd.apache.org/docs/current/mod/mod_lua.html | |
This is the default method name for Lua handlers, see the optional | |
function-name in the LuaMapHandler directive to choose a different | |
entry point. | |
--]] | |
function handle(r) | |
r.content_type = "text/plain" | |
if r.method == 'GET' then | |
r:puts("Hello Lua World!\n") | |
for k, v in pairs( r:parseargs() ) do | |
r:puts( string.format("%s: %s\n", k, v) ) | |
end | |
elseif r.method == 'POST' then | |
r:puts("Hello Lua World!\n") | |
for k, v in pairs( r:parsebody() ) do | |
r:puts( string.format("%s: %s\n", k, v) ) | |
end | |
elseif r.method == 'PUT' then | |
-- use our own Error contents | |
r:puts("Unsupported HTTP method " .. r.method) | |
r.status = 405 | |
return apache2.ok | |
else | |
-- use the ErrorDocument | |
return 501 | |
end | |
return apache2.OK | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment