]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_lua.html.en
Rebuilds various other modifications from the last few days.
[apache] / docs / manual / mod / mod_lua.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5               This file is generated from xml source: DO NOT EDIT
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7       -->
8 <title>mod_lua - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
13 <body>
14 <div id="page-header">
15 <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>
16 <p class="apache">Apache HTTP Server Version 2.5</p>
17 <img alt="" src="../images/feather.gif" /></div>
18 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
19 <div id="path">
20 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Modules</a></div>
21 <div id="page-content">
22 <div id="preamble"><h1>Apache Module mod_lua</h1>
23 <div class="toplang">
24 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English">&nbsp;en&nbsp;</a></p>
25 </div>
26 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides Lua hooks into various portions of the httpd
27 request processing</td></tr>
28 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
29 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>lua_module</td></tr>
30 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_lua.c</td></tr>
31 <tr><th><a href="module-dict.html#Compatibility">Compatibility:</a></th><td>2.3 and later</td></tr></table>
32 <h3>Summary</h3>
33
34 <p>This module allows the server to be extended with scripts written in the
35 Lua programming language.  The extension points (hooks) available with
36 <code class="module"><a href="../mod/mod_lua.html">mod_lua</a></code> include many of the hooks available to
37 natively compiled Apache HTTP Server modules, such as mapping requests to
38 files, generating dynamic responses, access control, authentication, and
39 authorization</p>
40
41 <p>More information on the Lua programming language can be found at the
42 <a href="http://www.lua.org/">the Lua website</a>.</p>
43
44 <div class="note"><code>mod_lua</code> is still in experimental state.
45 Until it is declared stable, usage and behavior may change
46 at any time, even between stable releases of the 2.4.x series.
47 Be sure to check the CHANGES file before upgrading.</div>
48
49 </div>
50 <div id="quickview"><h3 class="directives">Directives</h3>
51 <ul id="toc">
52 <li><img alt="" src="../images/down.gif" /> <a href="#luacodecache">LuaCodeCache</a></li>
53 <li><img alt="" src="../images/down.gif" /> <a href="#luahookaccesschecker">LuaHookAccessChecker</a></li>
54 <li><img alt="" src="../images/down.gif" /> <a href="#luahookauthchecker">LuaHookAuthChecker</a></li>
55 <li><img alt="" src="../images/down.gif" /> <a href="#luahookcheckuserid">LuaHookCheckUserID</a></li>
56 <li><img alt="" src="../images/down.gif" /> <a href="#luahookfixups">LuaHookFixups</a></li>
57 <li><img alt="" src="../images/down.gif" /> <a href="#luahookinsertfilter">LuaHookInsertFilter</a></li>
58 <li><img alt="" src="../images/down.gif" /> <a href="#luahookmaptostorage">LuaHookMapToStorage</a></li>
59 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktranslatename">LuaHookTranslateName</a></li>
60 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktypechecker">LuaHookTypeChecker</a></li>
61 <li><img alt="" src="../images/down.gif" /> <a href="#luainherit">LuaInherit</a></li>
62 <li><img alt="" src="../images/down.gif" /> <a href="#luamaphandler">LuaMapHandler</a></li>
63 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagecpath">LuaPackageCPath</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagepath">LuaPackagePath</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#luaquickhandler">LuaQuickHandler</a></li>
66 <li><img alt="" src="../images/down.gif" /> <a href="#luaroot">LuaRoot</a></li>
67 <li><img alt="" src="../images/down.gif" /> <a href="#luascope">LuaScope</a></li>
68 </ul>
69 <h3>Topics</h3>
70 <ul id="topics">
71 <li><img alt="" src="../images/down.gif" /> <a href="#basicconf">Basic Configuration</a></li>
72 <li><img alt="" src="../images/down.gif" /> <a href="#writinghandlers">Writing Handlers</a></li>
73 <li><img alt="" src="../images/down.gif" /> <a href="#writinghooks">Writing Hooks</a></li>
74 <li><img alt="" src="../images/down.gif" /> <a href="#datastructures">Data Structures</a></li>
75 <li><img alt="" src="../images/down.gif" /> <a href="#logging">Logging Functions</a></li>
76 <li><img alt="" src="../images/down.gif" /> <a href="#apache2">apache2 Package</a></li>
77 </ul></div>
78 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
79 <div class="section">
80 <h2><a name="basicconf" id="basicconf">Basic Configuration</a></h2>
81
82 <p>The basic module loading directive is</p>
83
84 <div class="example"><p><code>
85     LoadModule lua_module modules/mod_lua.so
86 </code></p></div>
87
88 <p>
89 <code>mod_lua</code> provides a handler named <code>lua-script</code>,
90 which can be used with an <code>AddHandler</code> directive:</p>
91
92 <div class="example"><p><code>
93 AddHandler lua-script .lua
94 </code></p></div>
95
96 <p>
97 This will cause <code>mod_lua</code> to handle requests for files
98 ending in <code>.lua</code> by invoking that file's
99 <code>handle</code> function.
100 </p>
101
102 <p>For more flexibility, see <code class="directive">LuaMapHandler</code>.
103 </p>
104
105 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
106 <div class="section">
107 <h2><a name="writinghandlers" id="writinghandlers">Writing Handlers</a></h2>
108 <p> In the Apache HTTP Server API, the handler is a specific kind of hook
109 responsible for generating the response.  Examples of modules that include a
110 handler 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>,
111 and <code class="module"><a href="../mod/mod_status.html">mod_status</a></code>.</p>
112
113 <p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
114 just evaluating a script body CGI style. A handler function looks
115 something like this:</p>
116
117 <div class="example"><h3>example.lua</h3><pre>
118 -- example handler
119
120 require "string"
121
122 --[[
123      This is the default method name for Lua handlers, see the optional
124      function-name in the LuaMapHandler directive to choose a different
125      entry point.
126 --]]
127 function handle(r)
128     r.content_type = "text/plain"
129     r:puts("Hello Lua World!\n")
130
131     if r.method == 'GET' then
132         for k, v in pairs( r:parseargs() ) do
133             r:puts( string.format("%s: %s", k, v) )
134         end
135     elseif r.method == 'POST' then
136         for k, v in pairs( r:parsebody() ) do
137             r:puts( string.format("%s: %s", k, v) )
138         end
139     else
140         r:puts("unknown HTTP method " .. r.method)
141     end
142 end
143 </pre></div>
144
145 <p>
146 This handler function just prints out the uri or form encoded
147 arguments to a plaintext page.
148 </p>
149
150 <p>
151 This means (and in fact encourages) that you can have multiple
152 handlers (or hooks, or filters) in the same script.
153 </p>
154
155 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
156 <div class="section">
157 <h2><a name="writinghooks" id="writinghooks">Writing Hooks</a></h2>
158
159 <p>Hook functions are how modules (and Lua scripts) participate in the
160 processing of requests. Each type of hook exposed by the server exists for
161 a specific purposes such as mapping requests to the filesystem,
162 performing access control, or setting mimetypes.  General purpose hooks
163 that simply run at handy times in the request lifecycle exist as well.</p>
164
165 <p>Hook functions are passed the request object as their only argument.
166 They can return any value, depending on the hook, but most commonly
167 they'll return OK, DONE, or DECLINED, which you can write in lua as
168 <code>apache2.OK</code>, <code>apache2.DONE</code>, or
169 <code>apache2.DECLINED</code>, or else an HTTP status code.</p>
170
171 <div class="example"><h3>translate_name.lua</h3><pre>
172 -- example hook that rewrites the URI to a filesystem path.
173
174 require 'apache2'
175
176 function translate_name(r)
177     if r.uri == "/translate-name" then
178         r.filename = r.document_root .. "/find_me.txt"
179         return apache2.OK
180     end
181     -- we don't care about this URL, give another module a chance
182     return apache2.DECLINED
183 end
184 </pre></div>
185
186 <div class="example"><h3>translate_name2.lua</h3><pre>
187 --[[ example hook that rewrites one URI to another URI. It returns a
188      apache2.DECLINED to give other URL mappers a chance to work on the
189      substitution, including the core translate_name hook which maps based
190      on the DocumentRoot.
191
192      Note: It is currently undefined as to whether this runs before or after
193      mod_alias.
194 --]]
195
196 require 'apache2'
197
198 function translate_name(r)
199     if r.uri == "/translate-name" then
200         r.uri = "/find_me.txt"
201         return apache2.DECLINED
202     end
203     return apache2.DECLINED
204 end
205 </pre></div>
206 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
207 <div class="section">
208 <h2><a name="datastructures" id="datastructures">Data Structures</a></h2>
209
210 <dl>
211 <dt>request_rec</dt>
212         <dd>
213         <p>The request_rec is mapped in as a userdata. It has a metatable
214         which lets you do useful things with it. For the most part it
215         has the same fields as the request_rec struct (see httpd.h
216         until we get better docs here) many of which are writeable as
217         well as readable.  (The table fields' content can be changed, but the
218         fields themselves cannot be set to different tables.)</p>
219
220         <table class="bordered">
221
222         <tr>
223           <th><strong>Name</strong></th>
224           <th><strong>Lua type</strong></th>
225           <th><strong>Writable</strong></th>
226         </tr>
227         <tr>
228           <td><code>ap_auth_type</code></td>
229           <td>string</td>
230           <td>no</td>
231         </tr>
232         <tr>
233           <td><code>args</code></td>
234           <td>string</td>
235           <td>yes</td>
236         </tr>
237         <tr>
238           <td><code>assbackwards</code></td>
239           <td>boolean</td>
240           <td>no</td>
241         </tr>
242
243         <tr>
244           <td><code>canonical_filename</code></td>
245           <td>string</td>
246           <td>no</td>
247         </tr>
248         <tr>
249           <td><code>content_encoding</code></td>
250           <td>string</td>
251           <td>no</td>
252         </tr>
253         <tr>
254           <td><code>content_type</code></td>
255           <td>string</td>
256           <td>yes</td>
257         </tr>
258
259         <tr>
260           <td><code>document_root</code></td>
261           <td>string</td>
262           <td>no</td>
263         </tr>
264         <tr>
265           <td><code>err_headers_out</code></td>
266           <td>table</td>
267           <td>no</td>
268         </tr>
269         <tr>
270           <td><code>filename</code></td>
271           <td>string</td>
272           <td>yes</td>
273         </tr>
274         <tr>
275           <td><code>handler</code></td>
276           <td>string</td>
277           <td>yes</td>
278         </tr>
279
280         <tr>
281           <td><code>headers_in</code></td>
282           <td>table</td>
283           <td>yes</td>
284         </tr>
285         <tr>
286           <td><code>headers_out</code></td>
287           <td>table</td>
288           <td>yes</td>
289         </tr>
290         <tr>
291           <td><code>hostname</code></td>
292           <td>string</td>
293           <td>no</td>
294         </tr>
295         <tr>
296           <td><code>method</code></td>
297           <td>string</td>
298           <td>no</td>
299         </tr>
300         <tr>
301           <td><code>notes</code></td>
302           <td>table</td>
303           <td>yes</td>
304         </tr>
305         <tr>
306           <td><code>path_info</code></td>
307           <td>string</td>
308           <td>no</td>
309         </tr>
310         <tr>
311           <td><code>protocol</code></td>
312           <td>string</td>
313           <td>no</td>
314         </tr>
315         <tr>
316           <td><code>proxyreq</code></td>
317           <td>string</td>
318           <td>yes</td>
319         </tr>
320         <tr>
321           <td><code>range</code></td>
322           <td>string</td>
323           <td>no</td>
324         </tr>
325         <tr>
326           <td><code>subprocess_env</code></td>
327           <td>table</td>
328           <td>yes</td>
329         </tr>
330         <tr>
331           <td><code>status</code></td>
332           <td>number</td>
333           <td>yes</td>
334         </tr>
335         <tr>
336           <td><code>the_request</code></td>
337           <td>string</td>
338           <td>no</td>
339         </tr>
340         <tr>
341           <td><code>unparsed_uri</code></td>
342           <td>string</td>
343           <td>no</td>
344         </tr>
345         <tr>
346           <td><code>uri</code></td>
347           <td>string</td>
348           <td>yes</td>
349         </tr>
350         <tr>
351           <td><code>user</code></td>
352           <td>string</td>
353           <td>yes</td>
354         </tr>
355         </table>
356
357         <p>The request_rec has (at least) the following methods:</p>
358
359         <div class="example"><p><code>
360         r:addoutputfilter(name|function) -- add an output filter
361         </code></p></div>
362
363         <div class="example"><p><code>
364         r:parseargs() -- returns a lua table containing the request's
365                          query string arguments
366         </code></p></div>
367
368         <div class="example"><p><code>
369         r:parsebody() -- parse the request body as a POST and return
370                          a lua table
371         </code></p></div>
372
373         <div class="example"><p><code>
374         r:puts("hello", " world", "!") -- print to response body
375         </code></p></div>
376
377         <div class="example"><p><code>
378         r:write("a single string") -- print to response body
379         </code></p></div>
380         </dd>
381     </dl>
382
383 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
384 <div class="section">
385 <h2><a name="logging" id="logging">Logging Functions</a></h2>
386
387 <div class="example"><p><code>
388         -- examples of logging messages<br />
389         r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
390         r:debug("This is a debug log message")<br />
391         r:info("This is an info log message")<br />
392         r:notice("This is an notice log message")<br />
393         r:warn("This is an warn log message")<br />
394         r:err("This is an err log message")<br />
395         r:alert("This is an alert log message")<br />
396         r:crit("This is an crit log message")<br />
397         r:emerg("This is an emerg log message")<br />
398 </code></p></div>
399
400 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
401 <div class="section">
402 <h2><a name="apache2" id="apache2">apache2 Package</a></h2>
403 <p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
404 <dl>
405   <dt>apache2.OK</dt>
406   <dd>internal constant OK.  Handlers should return this if they've
407   handled the request.</dd>
408   <dt>apache2.DECLINED</dt>
409   <dd>internal constant DECLINED.  Handlers should return this if
410   they are not going to handle the request.</dd>
411   <dt>apache2.DONE</dt>
412   <dd>internal constant DONE.</dd>
413   <dt>apache2.version</dt>
414   <dd>Apache HTTP server version string</dd>
415   <dt>apache2.HTTP_MOVED_TEMPORARILY</dt>
416   <dd>HTTP status code</dd>
417   <dt>apache2.PROXYREQ_NONE, apache2.PROXYREQ_PROXY, apache2.PROXYREQ_REVERSE, apache2.PROXYREQ_RESPONSE</dt>
418   <dd>internal constants used by <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></dd>
419 </dl>
420 <p>(Other HTTP status codes are not yet implemented.)</p>
421 </div>
422 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
423 <div class="directive-section"><h2><a name="LuaCodeCache" id="LuaCodeCache">LuaCodeCache</a> <a name="luacodecache" id="luacodecache">Directive</a></h2>
424 <table class="directive">
425 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configure the compiled code cache.</td></tr>
426 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaCodeCache stat|forever|never</code></td></tr>
427 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaCodeCache stat</code></td></tr>
428 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
429 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
430 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
431 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
432 </table><p>
433     Specify the behavior of the in-memory code cache. The default
434     is stat, which stats the top level script (not any included
435     ones) each time that file is needed, and reloads it if the
436     modified time indicates it is newer than the one it has
437     already loaded. The other values cause it to keep the file
438     cached forever (don't stat and replace) or to never cache the
439     file.</p>
440
441     <p>In general stat or forever is good for production, and stat or never
442     for development.</p>
443
444     <div class="example"><h3>Examples:</h3><p><code>
445         LuaCodeCache stat<br />
446         LuaCodeCache forever<br />
447         LuaCodeCache never<br />
448     </code></p></div>
449
450
451 </div>
452 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
453 <div class="directive-section"><h2><a name="LuaHookAccessChecker" id="LuaHookAccessChecker">LuaHookAccessChecker</a> <a name="luahookaccesschecker" id="luahookaccesschecker">Directive</a></h2>
454 <table class="directive">
455 <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>
456 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAccessChecker  /path/to/lua/script.lua  hook_function_name [early|late]</code></td></tr>
457 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
458 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
459 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
460 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
461 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
462 </table>
463 <p>Add your hook to the access_checker phase.  An access checker
464 hook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
465    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
466    control when this script runs relative to other modules.</p></div>
467
468 </div>
469 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
470 <div class="directive-section"><h2><a name="LuaHookAuthChecker" id="LuaHookAuthChecker">LuaHookAuthChecker</a> <a name="luahookauthchecker" id="luahookauthchecker">Directive</a></h2>
471 <table class="directive">
472 <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>
473 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookAuthChecker  /path/to/lua/script.lua hook_function_name [early|late]</code></td></tr>
474 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
475 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
476 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
477 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
478 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
479 </table>
480 <p>Invoke a lua function in the auth_checker phase of processing
481 a request.  This can be used to implement arbitrary authentication
482 and authorization checking.  A very simple example:
483 </p>
484 <div class="example"><pre>
485 require 'apache2'
486
487 -- fake authcheck hook
488 -- If request has no auth info, set the response header and
489 -- return a 401 to ask the browser for basic auth info.
490 -- If request has auth info, don't actually look at it, just
491 -- pretend we got userid 'foo' and validated it.
492 -- Then check if the userid is 'foo' and accept the request.
493 function authcheck_hook(r)
494
495    -- look for auth info
496    auth = r.headers_in['Authorization']
497    if auth ~= nil then
498      -- fake the user
499      r.user = 'foo'
500    end
501
502    if r.user == nil then
503       r:debug("authcheck: user is nil, returning 401")
504       r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
505       return 401
506    elseif r.user == "foo" then
507       r:debug('user foo: OK')
508    else
509       r:debug("authcheck: user='" .. r.user .. "'")
510       r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
511       return 401
512    end
513    return apache2.OK
514 end
515 </pre></div>
516    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
517    control when this script runs relative to other modules.</p></div>
518
519 </div>
520 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
521 <div class="directive-section"><h2><a name="LuaHookCheckUserID" id="LuaHookCheckUserID">LuaHookCheckUserID</a> <a name="luahookcheckuserid" id="luahookcheckuserid">Directive</a></h2>
522 <table class="directive">
523 <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>
524 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookCheckUserID  /path/to/lua/script.lua hook_function_name [early|late]</code></td></tr>
525 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
526 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
527 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
528 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
529 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
530 </table><p>...</p>
531    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
532    control when this script runs relative to other modules.</p></div>
533
534 </div>
535 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
536 <div class="directive-section"><h2><a name="LuaHookFixups" id="LuaHookFixups">LuaHookFixups</a> <a name="luahookfixups" id="luahookfixups">Directive</a></h2>
537 <table class="directive">
538 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the fixups phase of request
539 processing</td></tr>
540 <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>
541 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
542 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
543 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
544 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
545 </table>
546 <p>
547     Just like LuaHookTranslateName, but executed at the fixups phase
548 </p>
549
550 </div>
551 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
552 <div class="directive-section"><h2><a name="LuaHookInsertFilter" id="LuaHookInsertFilter">LuaHookInsertFilter</a> <a name="luahookinsertfilter" id="luahookinsertfilter">Directive</a></h2>
553 <table class="directive">
554 <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>
555 <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>
556 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
557 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
558 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
559 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
560 </table><p>Not Yet Implemented</p>
561 </div>
562 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
563 <div class="directive-section"><h2><a name="LuaHookMapToStorage" id="LuaHookMapToStorage">LuaHookMapToStorage</a> <a name="luahookmaptostorage" id="luahookmaptostorage">Directive</a></h2>
564 <table class="directive">
565 <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>
566 <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>
567 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
568 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
569 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
570 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
571 </table><p>...</p>
572 </div>
573 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
574 <div class="directive-section"><h2><a name="LuaHookTranslateName" id="LuaHookTranslateName">LuaHookTranslateName</a> <a name="luahooktranslatename" id="luahooktranslatename">Directive</a></h2>
575 <table class="directive">
576 <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>
577 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookTranslateName  /path/to/lua/script.lua  hook_function_name [early|late]</code></td></tr>
578 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
579 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
580 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
581 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
582 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>The optional third argument is supported in 2.3.15 and later</td></tr>
583 </table><p>
584     Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
585     request processing. The hook function receives a single
586     argument, the request_rec, and should return a status code,
587     which is either an HTTP error code, or the constants defined
588     in the apache2 module: apache2.OK, apache2.DECLINED, or
589     apache2.DONE. </p>
590
591     <p>For those new to hooks, basically each hook will be invoked
592     until one of them returns apache2.OK. If your hook doesn't
593     want to do the translation it should just return
594     apache2.DECLINED. If the request should stop processing, then
595     return apache2.DONE.</p>
596
597     <p>Example:</p>
598
599 <div class="example"><pre>
600 # httpd.conf
601 LuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
602
603 -- /scripts/conf/hooks.lua --
604 require "apache2"
605 function silly_mapper(r)
606     if r.uri == "/" then
607         r.filename = "/var/www/home.lua"
608         return apache2.OK
609     else
610         return apache2.DECLINED
611     end
612 end
613 </pre></div>
614
615    <div class="note"><h3>Context</h3><p>This directive is not valid in <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</a></code>, <code class="directive"><a href="../mod/core.html#files">&lt;Files&gt;</a></code>, or htaccess
616    context.</p></div>
617
618    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
619    control when this script runs relative to other modules.</p></div>
620
621
622 </div>
623 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
624 <div class="directive-section"><h2><a name="LuaHookTypeChecker" id="LuaHookTypeChecker">LuaHookTypeChecker</a> <a name="luahooktypechecker" id="luahooktypechecker">Directive</a></h2>
625 <table class="directive">
626 <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>
627 <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>
628 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
629 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
630 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
631 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
632 </table><p>...</p>
633 </div>
634 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
635 <div class="directive-section"><h2><a name="LuaInherit" id="LuaInherit">LuaInherit</a> <a name="luainherit" id="luainherit">Directive</a></h2>
636 <table class="directive">
637 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Controls how parent configuration sections are merged into children</td></tr>
638 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaInherit none|parent-first|parent-last</code></td></tr>
639 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaInherit parent-first</code></td></tr>
640 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
641 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
642 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
643 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
644 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.4.0 and later</td></tr>
645 </table><p>By default, if LuaHook* directives are used in overlapping
646     Directory or Location configuration sections, the scripts defined in the
647     more specific section are run <em>after</em> those defined in the more
648     generic section (LuaInherit parent-first).  You can reverse this order, or
649     make the parent context not apply at all.</p>
650     
651     <p> In previous 2.3.x releases, the default was effectively to ignore LuaHook*
652     directives from parent configuration sections.</p>
653 </div>
654 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
655 <div class="directive-section"><h2><a name="LuaMapHandler" id="LuaMapHandler">LuaMapHandler</a> <a name="luamaphandler" id="luamaphandler">Directive</a></h2>
656 <table class="directive">
657 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Map a path to a lua handler</td></tr>
658 <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>
659 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
660 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
661 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
662 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
663 </table>
664     <p>This directive matches a uri pattern to invoke a specific
665     handler function in a specific file. It uses PCRE regular
666     expressions to match the uri, and supports interpolating
667     match groups into both the file path and the function name
668     be careful writing your regular expressions to avoid security
669     issues.</p>
670    <div class="example"><h3>Examples:</h3><p><code>
671     LuaMapHandler /(\w+)/(/w+) /scripts/$1.lua handle_$2
672    </code></p></div>
673         <p>This would match uri's such as /photos/show?id=9
674         to the file /scripts/photos.lua and invoke the
675         handler function handle_show on the lua vm after
676         loading that file.</p>
677
678 <div class="example"><p><code>
679     LuaMapHandler /bingo /scripts/wombat.lua
680 </code></p></div>
681         <p>This would invoke the "handle" function, which
682         is the default if no specific function name is
683         provided.</p>
684
685 </div>
686 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
687 <div class="directive-section"><h2><a name="LuaPackageCPath" id="LuaPackageCPath">LuaPackageCPath</a> <a name="luapackagecpath" id="luapackagecpath">Directive</a></h2>
688 <table class="directive">
689 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.cpath</td></tr>
690 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackageCPath /path/to/include/?.soa</code></td></tr>
691 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
692 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
693 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
694 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
695 </table>
696     <p>Add a path to lua's shared library search path. Follows the same
697     conventions as lua. This just munges the package.cpath in the
698     lua vms.</p>
699
700
701 </div>
702 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
703 <div class="directive-section"><h2><a name="LuaPackagePath" id="LuaPackagePath">LuaPackagePath</a> <a name="luapackagepath" id="luapackagepath">Directive</a></h2>
704 <table class="directive">
705 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.path</td></tr>
706 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackagePath /path/to/include/?.lua</code></td></tr>
707 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
708 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
709 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
710 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
711 </table><p>Add a path to lua's module search path. Follows the same
712     conventions as lua. This just munges the package.path in the
713     lua vms.</p>
714
715     <div class="example"><h3>Examples:</h3><p><code>
716         LuaPackagePath /scripts/lib/?.lua<br />
717         LuaPackagePath /scripts/lib/?/init.lua
718     </code></p></div>
719
720 </div>
721 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
722 <div class="directive-section"><h2><a name="LuaQuickHandler" id="LuaQuickHandler">LuaQuickHandler</a> <a name="luaquickhandler" id="luaquickhandler">Directive</a></h2>
723 <table class="directive">
724 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the quick handler of request processing</td></tr>
725 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code /></td></tr>
726 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
727 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
728 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
729 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
730 </table><p>...</p>
731    <div class="note"><h3>Context</h3><p>This directive is not valid in <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</a></code>, <code class="directive"><a href="../mod/core.html#files">&lt;Files&gt;</a></code>, or htaccess
732    context.</p></div>
733
734 </div>
735 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
736 <div class="directive-section"><h2><a name="LuaRoot" id="LuaRoot">LuaRoot</a> <a name="luaroot" id="luaroot">Directive</a></h2>
737 <table class="directive">
738 <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>
739 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaRoot /path/to/a/directory</code></td></tr>
740 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
741 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
742 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
743 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
744 </table>
745     <p>Specify the base path which will be used to evaluate all
746     relative paths within mod_lua. If not specified they
747     will be resolved relative to the current working directory,
748     which may not always work well for a server.</p>
749
750 </div>
751 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
752 <div class="directive-section"><h2><a name="LuaScope" id="LuaScope">LuaScope</a> <a name="luascope" id="luascope">Directive</a></h2>
753 <table class="directive">
754 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>One of once, request, conn, server -- default is once</td></tr>
755 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaScope once|request|conn|server [max|min max]</code></td></tr>
756 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaScope once</code></td></tr>
757 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
758 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
759 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
760 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
761 </table>
762     <p>Specify the lifecycle scope of the Lua interpreter which will
763     be used by handlers in this "Directory." The default is "once"</p>
764
765    <dl>
766     <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
767
768     <dt>request:</dt> <dd>use the interpreter to handle anything based on
769              the same file within this request, which is also
770              request scoped.</dd>
771
772     <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
773
774     <dt>server:</dt>  <dd>This one is different than others because the
775             server scope is quite long lived, and multiple threads
776             will have the same server_rec. To accommodate this
777             server scoped interpreter are stored in an apr
778             resource list. The min and max arguments are intended
779             to specify the pool size, but are unused at this time.</dd>
780    </dl>
781
782 </div>
783 </div>
784 <div class="bottomlang">
785 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English">&nbsp;en&nbsp;</a></p>
786 </div><div id="footer">
787 <p class="apache">Copyright 2012 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>
788 <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>
789 </body></html>