mod_lua.html.en revision fc57cc74ee4e73618f74a7a62ea6ac77546666da
fb51a6b789d85113d0976148685b0063c294220drbowen<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
77a0265761f1bec2aaa0b4116c644f8066e349e3rbowen XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen This file is generated from xml source: DO NOT EDIT
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<link href="/images/favicon.ico" rel="shortcut icon" /></head>
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.3</a> > <a href="./">Modules</a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<p><span>Available Languages: </span><a href="/en/mod/mod_lua.html" title="English"> en </a></p>
fb51a6b789d85113d0976148685b0063c294220drbowen<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides Lua hooks into various portions of the httpd
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>lua_module</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_lua.c</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>2.3 and later</td></tr></table>
fb51a6b789d85113d0976148685b0063c294220drbowen<p>This module allows the server to be extended with scripts written in the
92e5d4326ae44f79da5cb049470daba604506846poirierLua programming language. The extension points (hooks) available with
92e5d4326ae44f79da5cb049470daba604506846poirier<code class="module"><a href="/mod/mod_lua.html">mod_lua</a></code> include many of the hooks available to
92e5d4326ae44f79da5cb049470daba604506846poiriernatively compiled Apache HTTP Server modules, such as mapping requests to
fb51a6b789d85113d0976148685b0063c294220drbowenfiles, generating dynamic responses, access control, authentication, and
fb51a6b789d85113d0976148685b0063c294220drbowenauthorization</p>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<p>More information on the Lua programming language can be found at the
fb51a6b789d85113d0976148685b0063c294220drbowen<a href="http://www.lua.org/">the Lua website</a>.</p>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="note"><code>mod_lua</code> is still in experimental state.
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowenUntil it is declared stable, usage and behavior may change
2219c51bf0756c2f6f7deb88a13baf30f141c12epoirierat any time.</div>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<div id="quickview"><h3 class="directives">Directives</h3>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<li><img alt="" src="/images/down.gif" /> <a href="#luacodecache">LuaCodeCache</a></li>
fb51a6b789d85113d0976148685b0063c294220drbowen<li><img alt="" src="/images/down.gif" /> <a href="#luahookaccesschecker">LuaHookAccessChecker</a></li>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<li><img alt="" src="/images/down.gif" /> <a href="#luahookauthchecker">LuaHookAuthChecker</a></li>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<li><img alt="" src="/images/down.gif" /> <a href="#luahookcheckuserid">LuaHookCheckUserID</a></li>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<li><img alt="" src="/images/down.gif" /> <a href="#luahookfixups">LuaHookFixups</a></li>
fb51a6b789d85113d0976148685b0063c294220drbowen<li><img alt="" src="/images/down.gif" /> <a href="#luahookinsertfilter">LuaHookInsertFilter</a></li>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<li><img alt="" src="/images/down.gif" /> <a href="#luahookmaptostorage">LuaHookMapToStorage</a></li>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<li><img alt="" src="/images/down.gif" /> <a href="#luahooktranslatename">LuaHookTranslateName</a></li>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<li><img alt="" src="/images/down.gif" /> <a href="#luahooktypechecker">LuaHookTypeChecker</a></li>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<li><img alt="" src="/images/down.gif" /> <a href="#luamaphandler">LuaMapHandler</a></li>
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<li><img alt="" src="/images/down.gif" /> <a href="#luapackagecpath">LuaPackageCPath</a></li>
92e5d4326ae44f79da5cb049470daba604506846poirier<li><img alt="" src="/images/down.gif" /> <a href="#luapackagepath">LuaPackagePath</a></li>
92e5d4326ae44f79da5cb049470daba604506846poirier<li><img alt="" src="/images/down.gif" /> <a href="#luaquickhandler">LuaQuickHandler</a></li>
92e5d4326ae44f79da5cb049470daba604506846poirier<li><img alt="" src="/images/down.gif" /> <a href="#luaroot">LuaRoot</a></li>
92e5d4326ae44f79da5cb049470daba604506846poirier<li><img alt="" src="/images/down.gif" /> <a href="#luascope">LuaScope</a></li>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<li><img alt="" src="/images/down.gif" /> <a href="#basicconf">Basic Configuration</a></li>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<li><img alt="" src="/images/down.gif" /> <a href="#writinghandlers">Writing Handlers</a></li>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<li><img alt="" src="/images/down.gif" /> <a href="#writinghooks">Writing Hooks</a></li>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<li><img alt="" src="/images/down.gif" /> <a href="#datastructures">Data Structures</a></li>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<li><img alt="" src="/images/down.gif" /> <a href="#logging">Logging Functions</a></li>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<li><img alt="" src="/images/down.gif" /> <a href="#apache2">apache2 Package</a></li>
92e5d4326ae44f79da5cb049470daba604506846poirier<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
92e5d4326ae44f79da5cb049470daba604506846poirier<h2><a name="basicconf" id="basicconf">Basic Configuration</a></h2>
92e5d4326ae44f79da5cb049470daba604506846poirier<code>mod_lua</code> provides a handler named <code>lua-script</code>,
92e5d4326ae44f79da5cb049470daba604506846poirierwhich can be used with an <code>AddHandler</code> directive:</p>
92e5d4326ae44f79da5cb049470daba604506846poirierAddHandler lua-script .lua
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenThis will cause <code>mod_lua</code> to handle requests for files
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<p>For more flexibility, see <code class="directive">LuaMapHandler</code>.
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<h2><a name="writinghandlers" id="writinghandlers">Writing Handlers</a></h2>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<p> In the Apache HTTP Server API, the handler is a specific kind of hook
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenresponsible for generating the response. Examples of modules that include a
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenhandler are <code class="module"><a href="/mod/mod_proxy.html">mod_proxy</a></code>, <code class="module"><a href="/mod/mod_cgi.html">mod_cgi</a></code>,
92e5d4326ae44f79da5cb049470daba604506846poirierand <code class="module"><a href="/mod/mod_status.html">mod_status</a></code>.</p>
92e5d4326ae44f79da5cb049470daba604506846poirier<p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
92e5d4326ae44f79da5cb049470daba604506846poirierjust evaluating a script body CGI style. A handler function looks
92e5d4326ae44f79da5cb049470daba604506846poiriersomething like this:</p>
92e5d4326ae44f79da5cb049470daba604506846poirier-- example handler
92e5d4326ae44f79da5cb049470daba604506846poirierrequire "string"
92e5d4326ae44f79da5cb049470daba604506846poirier This is the default method name for Lua handlers, see the optional
92e5d4326ae44f79da5cb049470daba604506846poirier function-name in the LuaMapHandler directive to choose a different
92e5d4326ae44f79da5cb049470daba604506846poirier entry point.
92e5d4326ae44f79da5cb049470daba604506846poirierfunction handle(r)
92e5d4326ae44f79da5cb049470daba604506846poirier r:puts("Hello Lua World!\n")
92e5d4326ae44f79da5cb049470daba604506846poirier if r.method == 'GET' then
92e5d4326ae44f79da5cb049470daba604506846poirier for k, v in pairs( r:parseargs() ) do
92e5d4326ae44f79da5cb049470daba604506846poirier r:puts( string.format("%s: %s", k, v) )
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen elseif r.method == 'POST' then
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen for k, v in pairs( r:parsebody() ) do
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen r:puts( string.format("%s: %s", k, v) )
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen r:puts("unknown HTTP method " .. r.method)
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierThis handler function just prints out the uri or form encoded
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierarguments to a plaintext page.
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierThis means (and in fact encourages) that you can have multiple
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierhandlers (or hooks, or filters) in the same script.
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<h2><a name="writinghooks" id="writinghooks">Writing Hooks</a></h2>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<p>Hook functions are how modules (and Lua scripts) participate in the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierprocessing of requests. Each type of hook exposed by the server exists for
249cc9b3d83d3c60666269b90ecb9f1390d32165poiriera specific purposes such as mapping requests to the filesystem,
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierperforming access control, or setting mimetypes. General purpose hooks
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierthat simply run at handy times in the request lifecycle exist as well.</p>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<p>Hook functions are passed the request object as their only argument.
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierThey can return any value, depending on the hook, but most commonly
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierthey'll return OK, DONE, or DECLINED, which you can write in lua as
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<code>apache2.OK</code>, <code>apache2.DONE</code>, or
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<code>apache2.DECLINED</code>, or else an HTTP status code.</p>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<div class="example"><h3>translate_name.lua</h3><pre>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier-- example hook that rewrites the URI to a filesystem path.
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierrequire 'apache2'
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierfunction translate_name(r)
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier if r.uri == "/translate-name" then
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier -- we don't care about this URL, give another module a chance
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<div class="example"><h3>translate_name2.lua</h3><pre>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier--[[ example hook that rewrites one URI to another URI. It returns a
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier apache2.DECLINED to give other URL mappers a chance to work on the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier substitution, including the core translate_name hook which maps based
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier on the DocumentRoot.
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier Note: It is currently undefined as to whether this runs before or after
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierrequire 'apache2'
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierfunction translate_name(r)
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier if r.uri == "/translate-name" then
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<h2><a name="datastructures" id="datastructures">Data Structures</a></h2>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <p>The request_rec is mapped in as a userdata. It has a metatable
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier which lets you do useful things with it. For the most part it
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier has the same fields as the request_rec struct (see httpd.h
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier until we get better docs here) many of which are writeable as
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier well as readable. (The table fields' content can be changed, but the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier fields themselves cannot be set to different tables.)</p>
fb51a6b789d85113d0976148685b0063c294220drbowen <p>The request_rec has (at least) the following methods:</p>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen r:addoutputfilter(name|function) -- add an output filter
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic r:parseargs() -- returns a lua table containing the request's
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic query string arguments
fb51a6b789d85113d0976148685b0063c294220drbowen r:parsebody() -- parse the request body as a POST and return
c994f52ac80f9664d2940e5ccd9e77466572013frbowen a lua table
fb51a6b789d85113d0976148685b0063c294220drbowen r:puts("hello", " world", "!") -- print to response body
fb51a6b789d85113d0976148685b0063c294220drbowen r:write("a single string") -- print to response body
fb51a6b789d85113d0976148685b0063c294220drbowen</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<h2><a name="logging" id="logging">Logging Functions</a></h2>
c994f52ac80f9664d2940e5ccd9e77466572013frbowen -- examples of logging messages<br />
fb51a6b789d85113d0976148685b0063c294220drbowen r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
fb51a6b789d85113d0976148685b0063c294220drbowen r:debug("This is a debug log message")<br />
fb51a6b789d85113d0976148685b0063c294220drbowen r:info("This is an info log message")<br />
fb51a6b789d85113d0976148685b0063c294220drbowen r:notice("This is an notice log message")<br />
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen r:warn("This is an warn log message")<br />
fb51a6b789d85113d0976148685b0063c294220drbowen r:err("This is an err log message")<br />
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic r:alert("This is an alert log message")<br />
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic r:crit("This is an crit log message")<br />
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic r:emerg("This is an emerg log message")<br />
fb51a6b789d85113d0976148685b0063c294220drbowen</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<h2><a name="apache2" id="apache2">apache2 Package</a></h2>
fb51a6b789d85113d0976148685b0063c294220drbowen<p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
c994f52ac80f9664d2940e5ccd9e77466572013frbowen <dd>internal constant OK. Handlers should return this if they've
fb51a6b789d85113d0976148685b0063c294220drbowen handled the request.</dd>
fb51a6b789d85113d0976148685b0063c294220drbowen <dd>internal constant DECLINED. Handlers should return this if
fb51a6b789d85113d0976148685b0063c294220drbowen they are not going to handle the request.</dd>
fb51a6b789d85113d0976148685b0063c294220drbowen<p>(Other HTTP status codes are not yet implemented.)</p>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="directive-section"><h2><a name="LuaCodeCache" id="LuaCodeCache">LuaCodeCache</a> <a name="luacodecache" id="luacodecache">Directive</a></h2>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configure the compiled code cache.</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaCodeCache stat|forever|never</code></td></tr>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaCodeCache stat</code></td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen Specify the behavior of the in-memory code cache. The default
fb51a6b789d85113d0976148685b0063c294220drbowen is stat, which stats the top level script (not any included
c994f52ac80f9664d2940e5ccd9e77466572013frbowen ones) each time that file is needed, and reloads it if the
fb51a6b789d85113d0976148685b0063c294220drbowen modified time indicates it is newer than the one it has
c994f52ac80f9664d2940e5ccd9e77466572013frbowen already loaded. The other values cause it to keep the file
c994f52ac80f9664d2940e5ccd9e77466572013frbowen cached forever (don't stat and replace) or to never cache the
c994f52ac80f9664d2940e5ccd9e77466572013frbowen <p>In general stat or forever is good for production, and stat or never
fb51a6b789d85113d0976148685b0063c294220drbowen for development.</p>
fb51a6b789d85113d0976148685b0063c294220drbowen LuaCodeCache stat<br />
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen LuaCodeCache forever<br />
fb51a6b789d85113d0976148685b0063c294220drbowen LuaCodeCache never<br />
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="directive-section"><h2><a name="LuaHookAccessChecker" id="LuaHookAccessChecker">LuaHookAccessChecker</a> <a name="luahookaccesschecker" id="luahookaccesschecker">Directive</a></h2>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the access_checker phase of request processing</td></tr>
c994f52ac80f9664d2940e5ccd9e77466572013frbowen<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAccessChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
c994f52ac80f9664d2940e5ccd9e77466572013frbowen<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<p>Add your hook to the access_checker phase. An access checker
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowenhook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<div class="directive-section"><h2><a name="LuaHookAuthChecker" id="LuaHookAuthChecker">LuaHookAuthChecker</a> <a name="luahookauthchecker" id="luahookauthchecker">Directive</a></h2>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the auth_checker phase of request processing</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAuthChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<p>Invoke a lua function in the auth_checker phase of processing
fb51a6b789d85113d0976148685b0063c294220drbowena request. This can be used to implement arbitrary authentication
c994f52ac80f9664d2940e5ccd9e77466572013frbowenand authorization checking. A very simple example:
c994f52ac80f9664d2940e5ccd9e77466572013frbowenrequire 'apache2'
c994f52ac80f9664d2940e5ccd9e77466572013frbowen-- fake authcheck hook
c994f52ac80f9664d2940e5ccd9e77466572013frbowen-- If request has no auth info, set the response header and
c994f52ac80f9664d2940e5ccd9e77466572013frbowen-- return a 401 to ask the browser for basic auth info.
c994f52ac80f9664d2940e5ccd9e77466572013frbowen-- If request has auth info, don't actually look at it, just
c994f52ac80f9664d2940e5ccd9e77466572013frbowen-- pretend we got userid 'foo' and validated it.
c994f52ac80f9664d2940e5ccd9e77466572013frbowen-- Then check if the userid is 'foo' and accept the request.
c994f52ac80f9664d2940e5ccd9e77466572013frbowenfunction authcheck_hook(r)
fb51a6b789d85113d0976148685b0063c294220drbowen -- look for auth info
fb51a6b789d85113d0976148685b0063c294220drbowen auth = r.headers_in['Authorization']
fb51a6b789d85113d0976148685b0063c294220drbowen if auth ~= nil then
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen -- fake the user
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic if r.user == nil then
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic r:debug("authcheck: user is nil, returning 401")
fb51a6b789d85113d0976148685b0063c294220drbowen r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
fb51a6b789d85113d0976148685b0063c294220drbowen elseif r.user == "foo" then
fb51a6b789d85113d0976148685b0063c294220drbowen r:debug('user foo: OK')
fb51a6b789d85113d0976148685b0063c294220drbowen r:debug("authcheck: user='" .. r.user .. "'")
fb51a6b789d85113d0976148685b0063c294220drbowen r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="directive-section"><h2><a name="LuaHookCheckUserID" id="LuaHookCheckUserID">LuaHookCheckUserID</a> <a name="luahookcheckuserid" id="luahookcheckuserid">Directive</a></h2>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the check_user_id phase of request processing</td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookCheckUserID /path/to/lua/script.lua hook_function_name</code></td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
92e5d4326ae44f79da5cb049470daba604506846poirier<div class="directive-section"><h2><a name="LuaHookFixups" id="LuaHookFixups">LuaHookFixups</a> <a name="luahookfixups" id="luahookfixups">Directive</a></h2>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the fixups phase of request
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookFixups /path/to/lua/script.lua hook_function_name</code></td></tr>
92e5d4326ae44f79da5cb049470daba604506846poirier<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen Just like LuaHookTranslateName, but executed at the fixups phase
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<div class="directive-section"><h2><a name="LuaHookInsertFilter" id="LuaHookInsertFilter">LuaHookInsertFilter</a> <a name="luahookinsertfilter" id="luahookinsertfilter">Directive</a></h2>
3e30fa5f420fe7302a4cdcd79cb001958fd54a13rbowen<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the insert_filter phase of request processing</td></tr>
3e30fa5f420fe7302a4cdcd79cb001958fd54a13rbowen<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookInsertFilter /path/to/lua/script.lua hook_function_name</code></td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
3e30fa5f420fe7302a4cdcd79cb001958fd54a13rbowen<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
3e30fa5f420fe7302a4cdcd79cb001958fd54a13rbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen<div class="directive-section"><h2><a name="LuaHookMapToStorage" id="LuaHookMapToStorage">LuaHookMapToStorage</a> <a name="luahookmaptostorage" id="luahookmaptostorage">Directive</a></h2>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the map_to_storage phase of request processing</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookMapToStorage /path/to/lua/script.lua hook_function_name</code></td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen<div class="directive-section"><h2><a name="LuaHookTranslateName" id="LuaHookTranslateName">LuaHookTranslateName</a> <a name="luahooktranslatename" id="luahooktranslatename">Directive</a></h2>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the translate name phase of request processing</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTranslateName /path/to/lua/script.lua hook_function_name</code></td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
fb51a6b789d85113d0976148685b0063c294220drbowen request processing. The hook function receives a single
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen argument, the request_rec, and should return a status code,
fb51a6b789d85113d0976148685b0063c294220drbowen which is either an HTTP error code, or the constants defined
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic in the apache2 module: apache2.OK, apache2.DECLINED, or
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic <p>For those new to hooks, basically each hook will be invoked
fb51a6b789d85113d0976148685b0063c294220drbowen until one of them returns apache2.OK. If your hook doesn't
fb51a6b789d85113d0976148685b0063c294220drbowen want to do the translation it should just return
fb51a6b789d85113d0976148685b0063c294220drbowen apache2.DECLINED. If the request should stop processing, then
99e316bc4b9b2b5754165939ac14b6d16132cce1igalicLuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirierrequire "apache2"
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirierfunction silly_mapper(r)
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier if r.uri == "/" then
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<div class="directive-section"><h2><a name="LuaHookTypeChecker" id="LuaHookTypeChecker">LuaHookTypeChecker</a> <a name="luahooktypechecker" id="luahooktypechecker">Directive</a></h2>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the type_checker phase of request processing</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTypeChecker /path/to/lua/script.lua hook_function_name</code></td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<div class="directive-section"><h2><a name="LuaMapHandler" id="LuaMapHandler">LuaMapHandler</a> <a name="luamaphandler" id="luamaphandler">Directive</a></h2>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Map a path to a lua handler</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaMapHandler uri-pattern /path/to/lua/script.lua [function-name]</code></td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier <p>This directive matches a uri pattern to invoke a specific
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier handler function in a specific file. It uses PCRE regular
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier expressions to match the uri, and supports interpolating
768c8bcc0d91d1c3c04b0f80c309d31c6182fbf8poirier match groups into both the file path and the function name
fb51a6b789d85113d0976148685b0063c294220drbowen be careful writing your regular expressions to avoid security
fb51a6b789d85113d0976148685b0063c294220drbowen issues.</p>
fb51a6b789d85113d0976148685b0063c294220drbowen LuaMapHandler /(\w+)/(/w+) /scripts/$1.lua handle_$2
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic handler function handle_show on the lua vm after
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic loading that file.</p>
92e5d4326ae44f79da5cb049470daba604506846poirier <p>This would invoke the "handle" function, which
fb51a6b789d85113d0976148685b0063c294220drbowen is the default if no specific function name is
fb51a6b789d85113d0976148685b0063c294220drbowen provided.</p>
9cd56c73a0fd508522ba2f6bc6c9839c478c61c3rbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fb51a6b789d85113d0976148685b0063c294220drbowen<div class="directive-section"><h2><a name="LuaPackageCPath" id="LuaPackageCPath">LuaPackageCPath</a> <a name="luapackagecpath" id="luapackagecpath">Directive</a></h2>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.cpath</td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackageCPath /path/to/include/?.soa</code></td></tr>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen <p>Add a path to lua's shared library search path. Follows the same
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen conventions as lua. This just munges the package.cpath in the
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen lua vms.</p>
99e316bc4b9b2b5754165939ac14b6d16132cce1igalic<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen<div class="directive-section"><h2><a name="LuaPackagePath" id="LuaPackagePath">LuaPackagePath</a> <a name="luapackagepath" id="luapackagepath">Directive</a></h2>
6b4cd1f143d5d7244d2476d1e28456212faddb72rbowen<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.path</td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackagePath /path/to/include/?.lua</code></td></tr>
fb51a6b789d85113d0976148685b0063c294220drbowen<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
conventions as lua. This just munges the package.path in the
<div class="directive-section"><h2><a name="LuaQuickHandler" id="LuaQuickHandler">LuaQuickHandler</a> <a name="luaquickhandler" id="luaquickhandler">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the quick handler of request processing</td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<div class="directive-section"><h2><a name="LuaRoot" id="LuaRoot">LuaRoot</a> <a name="luaroot" id="luaroot">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Specify the base path for resolving relative paths for mod_lua directives</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaRoot /path/to/a/directory</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<div class="directive-section"><h2><a name="LuaScope" id="LuaScope">LuaScope</a> <a name="luascope" id="luascope">Directive</a></h2>
<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>One of once, request, conn, server -- default is once</td></tr>
<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaScope once|request|conn|server [max|min max]</code></td></tr>
<tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaScope once</code></td></tr>
<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
<p><span>Available Languages: </span><a href="/en/mod/mod_lua.html" title="English"> en </a></p>
<p class="apache">Copyright 2011 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="/faq/">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div>