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