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