mod_lua allows the Apache HTTP Server to be extended with scripts written in the Lua programming language. The extension points include request phase hooks, filtering mechanisms as well as the ability to develop web applications using Lua. It has native support for databases as well as a lot of built-in functions to ease working with requests.
Stuff to be written here...
mod_lua's interaction with Lua scripts is function-oriented, meaning mod_lua will first load the script, execute the flow of the script and then call a specific function (the default name of this is handle) to handle the request. Most mod_lua directives have the option to specify the name of the function to call, so that you can pool multiple handlers inside a single Lua file. Each call is passed a special table, called the request_rec, which holds information about the request as well as contains the built-in functions. The function can then manipulate the request and is expected to return a HTTP status code or an internal status value back to mod_lua, which will determine the outcome of the request.
An example mod_lua script could look like this:
function handle(r) if r.uri == "/" then r.content_type = "text/html" r:write("Hello world! You've reached the top level folder of this domain") end return apache2.OK end
Here are some of the standard return codes mod_lua expects to see from your Lua scripts:
|This is the standard return value, which means "we have handled this request, and everything went okay. You may proceed with serving the request/closing up"|
|This special value means that no request processing has taken place. It does not mean that the request is denied, but rather that our specific mod_lua script declined to handle it. It will be passed on to other hooks/handlers instead|
|This is another special value, which means "This request is DONE. Don't do any more processing of it, don't even log it in the access log. This can be used to terminate a request without resorting to returning an error to the client.|
|This is the standard "200 Okay" HTTP return code.|
|The HTTP status code for "Moved permanently". Use this to issue a permanent (cached) redirect|
|Like above, but only causes temporary redirects which will be re-evaluated upon each request.|
|"Authorization required". This is a useful return code for when working with, for instance, Basic Authorization|
|"Forbidden". This will tell the client that the resource is off access to it|
|"Not found". It's a 404, you know what it does!|
|Internal Server Error - return this code when stuff goes bad|