Skip to content

Instantly share code, notes, and snippets.

@erdoukki
Forked from james2doyle/apache.lua
Created August 13, 2021 11:44
Show Gist options
  • Select an option

  • Save erdoukki/f1c006692f572727f40162886c3e81e3 to your computer and use it in GitHub Desktop.

Select an option

Save erdoukki/f1c006692f572727f40162886c3e81e3 to your computer and use it in GitHub Desktop.

Revisions

  1. @james2doyle james2doyle created this gist Feb 14, 2015.
    32 changes: 32 additions & 0 deletions apache.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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