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