Skip to content

Instantly share code, notes, and snippets.

@erdoukki
Forked from james2doyle/apache.lua
Created August 13, 2021 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdoukki/f1c006692f572727f40162886c3e81e3 to your computer and use it in GitHub Desktop.
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
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