]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_lua.html.en
We need moar emails - format change
[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 Version 2.5</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.min.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/quickreference.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 class="warning"><h3>Warning</h3>
54 <p>This module holds a great deal of power over httpd, which is both a 
55 strength and a potential security risk. It is <strong>not</strong> recommended 
56 that you use this module on a server that is shared with users you do not 
57 trust, as it can be abused to change the internal workings of httpd.</p>
58 </div>
59
60 </div>
61 <div id="quickview"><h3>Topics</h3>
62 <ul id="topics">
63 <li><img alt="" src="../images/down.gif" /> <a href="#basicconf">Basic Configuration</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#writinghandlers">Writing Handlers</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#writingauthzproviders">Writing Authorization Providers</a></li>
66 <li><img alt="" src="../images/down.gif" /> <a href="#writinghooks">Writing Hooks</a></li>
67 <li><img alt="" src="../images/down.gif" /> <a href="#datastructures">Data Structures</a></li>
68 <li><img alt="" src="../images/down.gif" /> <a href="#functions">Built in functions</a></li>
69 <li><img alt="" src="../images/down.gif" /> <a href="#logging">Logging Functions</a></li>
70 <li><img alt="" src="../images/down.gif" /> <a href="#apache2">apache2 Package</a></li>
71 <li><img alt="" src="../images/down.gif" /> <a href="#modifying_buckets">Modifying contents with Lua filters</a></li>
72 <li><img alt="" src="../images/down.gif" /> <a href="#databases">Database connectivity</a></li>
73 </ul><h3 class="directives">Directives</h3>
74 <ul id="toc">
75 <li><img alt="" src="../images/down.gif" /> <a href="#luaauthzprovider">LuaAuthzProvider</a></li>
76 <li><img alt="" src="../images/down.gif" /> <a href="#luacodecache">LuaCodeCache</a></li>
77 <li><img alt="" src="../images/down.gif" /> <a href="#luahookaccesschecker">LuaHookAccessChecker</a></li>
78 <li><img alt="" src="../images/down.gif" /> <a href="#luahookauthchecker">LuaHookAuthChecker</a></li>
79 <li><img alt="" src="../images/down.gif" /> <a href="#luahookcheckuserid">LuaHookCheckUserID</a></li>
80 <li><img alt="" src="../images/down.gif" /> <a href="#luahookfixups">LuaHookFixups</a></li>
81 <li><img alt="" src="../images/down.gif" /> <a href="#luahookinsertfilter">LuaHookInsertFilter</a></li>
82 <li><img alt="" src="../images/down.gif" /> <a href="#luahooklog">LuaHookLog</a></li>
83 <li><img alt="" src="../images/down.gif" /> <a href="#luahookmaptostorage">LuaHookMapToStorage</a></li>
84 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktranslatename">LuaHookTranslateName</a></li>
85 <li><img alt="" src="../images/down.gif" /> <a href="#luahooktypechecker">LuaHookTypeChecker</a></li>
86 <li><img alt="" src="../images/down.gif" /> <a href="#luainherit">LuaInherit</a></li>
87 <li><img alt="" src="../images/down.gif" /> <a href="#luainputfilter">LuaInputFilter</a></li>
88 <li><img alt="" src="../images/down.gif" /> <a href="#luamaphandler">LuaMapHandler</a></li>
89 <li><img alt="" src="../images/down.gif" /> <a href="#luaoutputfilter">LuaOutputFilter</a></li>
90 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagecpath">LuaPackageCPath</a></li>
91 <li><img alt="" src="../images/down.gif" /> <a href="#luapackagepath">LuaPackagePath</a></li>
92 <li><img alt="" src="../images/down.gif" /> <a href="#luaquickhandler">LuaQuickHandler</a></li>
93 <li><img alt="" src="../images/down.gif" /> <a href="#luaroot">LuaRoot</a></li>
94 <li><img alt="" src="../images/down.gif" /> <a href="#luascope">LuaScope</a></li>
95 </ul>
96 <ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
97 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
98 <div class="directive-section"><h2><a name="LuaAuthzProvider" id="LuaAuthzProvider">LuaAuthzProvider</a> <a name="luaauthzprovider" id="luaauthzprovider">Directive</a></h2>
99 <table class="directive">
100 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Plug an authorization provider function into <code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code>
101 </td></tr>
102 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaAuthzProvider provider_name /path/to/lua/script.lua function_name</code></td></tr>
103 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
104 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
105 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
106 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.4.3 and later</td></tr>
107 </table>
108 <p>After a lua function has been registered as authorization provider, it can be used
109 with the <code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code> directive:</p>
110
111 <pre class="prettyprint lang-config">LuaRoot /usr/local/apache2/lua
112 LuaAuthzProvider foo authz.lua authz_check_foo
113 &lt;Location /&gt;
114   Require foo johndoe
115 &lt;/Location&gt;</pre>
116
117 <pre class="prettyprint lang-lua">require "apache2"
118 function authz_check_foo(r, who)
119     if r.user ~= who then return apache2.AUTHZ_DENIED
120     return apache2.AUTHZ_GRANTED
121 end</pre>
122
123
124
125
126 </div>
127 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
128 <div class="directive-section"><h2><a name="LuaCodeCache" id="LuaCodeCache">LuaCodeCache</a> <a name="luacodecache" id="luacodecache">Directive</a></h2>
129 <table class="directive">
130 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configure the compiled code cache.</td></tr>
131 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaCodeCache stat|forever|never</code></td></tr>
132 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaCodeCache stat</code></td></tr>
133 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
134 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
135 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
136 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
137 </table><p>
138     Specify the behavior of the in-memory code cache. The default
139     is stat, which stats the top level script (not any included
140     ones) each time that file is needed, and reloads it if the
141     modified time indicates it is newer than the one it has
142     already loaded. The other values cause it to keep the file
143     cached forever (don't stat and replace) or to never cache the
144     file.</p>
145
146     <p>In general stat or forever is good for production, and stat or never
147     for development.</p>
148
149     <div class="example"><h3>Examples:</h3><pre class="prettyprint lang-config">LuaCodeCache stat
150 LuaCodeCache forever
151 LuaCodeCache never</pre>
152 </div>
153
154
155 </div>
156 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
157 <div class="directive-section"><h2><a name="LuaHookAccessChecker" id="LuaHookAccessChecker">LuaHookAccessChecker</a> <a name="luahookaccesschecker" id="luahookaccesschecker">Directive</a></h2>
158 <table class="directive">
159 <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>
160 <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>
161 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
162 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
163 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
164 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
165 <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>
166 </table>
167 <p>Add your hook to the access_checker phase.  An access checker
168 hook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
169    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
170    control when this script runs relative to other modules.</p></div>
171
172 </div>
173 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
174 <div class="directive-section"><h2><a name="LuaHookAuthChecker" id="LuaHookAuthChecker">LuaHookAuthChecker</a> <a name="luahookauthchecker" id="luahookauthchecker">Directive</a></h2>
175 <table class="directive">
176 <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>
177 <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>
178 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
179 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
180 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
181 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
182 <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>
183 </table>
184 <p>Invoke a lua function in the auth_checker phase of processing
185 a request.  This can be used to implement arbitrary authentication
186 and authorization checking.  A very simple example:
187 </p>
188 <pre class="prettyprint lang-lua">require 'apache2'
189
190 -- fake authcheck hook
191 -- If request has no auth info, set the response header and
192 -- return a 401 to ask the browser for basic auth info.
193 -- If request has auth info, don't actually look at it, just
194 -- pretend we got userid 'foo' and validated it.
195 -- Then check if the userid is 'foo' and accept the request.
196 function authcheck_hook(r)
197
198    -- look for auth info
199    auth = r.headers_in['Authorization']
200    if auth ~= nil then
201      -- fake the user
202      r.user = 'foo'
203    end
204
205    if r.user == nil then
206       r:debug("authcheck: user is nil, returning 401")
207       r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
208       return 401
209    elseif r.user == "foo" then
210       r:debug('user foo: OK')
211    else
212       r:debug("authcheck: user='" .. r.user .. "'")
213       r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
214       return 401
215    end
216    return apache2.OK
217 end</pre>
218
219    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
220    control when this script runs relative to other modules.</p></div>
221
222 </div>
223 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
224 <div class="directive-section"><h2><a name="LuaHookCheckUserID" id="LuaHookCheckUserID">LuaHookCheckUserID</a> <a name="luahookcheckuserid" id="luahookcheckuserid">Directive</a></h2>
225 <table class="directive">
226 <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>
227 <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>
228 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
229 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
230 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
231 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
232 </table>
233 </div>
234 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
235 <div class="directive-section"><h2><a name="LuaHookFixups" id="LuaHookFixups">LuaHookFixups</a> <a name="luahookfixups" id="luahookfixups">Directive</a></h2>
236 <table class="directive">
237 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the fixups phase of a request
238 processing</td></tr>
239 <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>
240 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
241 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
242 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
243 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
244 </table>
245 <p>
246     Just like LuaHookTranslateName, but executed at the fixups phase
247 </p>
248
249 </div>
250 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
251 <div class="directive-section"><h2><a name="LuaHookInsertFilter" id="LuaHookInsertFilter">LuaHookInsertFilter</a> <a name="luahookinsertfilter" id="luahookinsertfilter">Directive</a></h2>
252 <table class="directive">
253 <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>
254 <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>
255 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
256 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
257 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
258 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
259 </table><p>Not Yet Implemented</p>
260 </div>
261 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
262 <div class="directive-section"><h2><a name="LuaHookLog" id="LuaHookLog">LuaHookLog</a> <a name="luahooklog" id="luahooklog">Directive</a></h2>
263 <table class="directive">
264 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the access log phase of a request
265 processing</td></tr>
266 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaHookLog  /path/to/lua/script.lua log_function_name</code></td></tr>
267 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
268 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
269 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
270 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
271 </table>
272 <p>
273     This simple logging hook allows you to run a function when httpd enters the 
274     logging phase of a request. With it, you can append data to your own logs, 
275     manipulate data before the regular log is written, or prevent a log entry 
276     from being created. To prevent the usual logging from happening, simply return
277     <code>apache2.DONE</code> in your logging handler, otherwise return 
278     <code>apache2.OK</code> to tell httpd to log as normal.
279 </p>
280 <p>Example:</p>
281 <pre class="prettyprint lang-config">LuaHookLog /path/to/script.lua logger</pre>
282
283 <pre class="prettyprint lang-lua">-- /path/to/script.lua --
284 function logger(r)
285     -- flip a coin:
286     -- If 1, then we write to our own Lua log and tell httpd not to log
287     -- in the main log.
288     -- If 2, then we just sanitize the output a bit and tell httpd to 
289     -- log the sanitized bits.
290
291     if math.random(1,2) == 1 then
292         -- Log stuff ourselves and don't log in the regular log
293         local f = io.open("/foo/secret.log", "a")
294         if f then
295             f:write("Something secret happened at " .. r.uri .. "\n")
296             f:close()
297         end
298         return apache2.DONE -- Tell httpd not to use the regular logging functions
299     else
300         r.uri = r.uri:gsub("somesecretstuff", "") -- sanitize the URI
301         return apache2.OK -- tell httpd to log it.
302     end
303 end</pre>
304
305
306 </div>
307 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
308 <div class="directive-section"><h2><a name="LuaHookMapToStorage" id="LuaHookMapToStorage">LuaHookMapToStorage</a> <a name="luahookmaptostorage" id="luahookmaptostorage">Directive</a></h2>
309 <table class="directive">
310 <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>
311 <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>
312 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
313 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
314 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
315 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
316 </table>
317     <p>Like <code class="directive">LuaHookTranslateName</code> but executed at the 
318     map-to-storage phase of a request. Modules like mod_cache run at this phase,
319     which makes for an interesting example on what to do here:</p>
320     <pre class="prettyprint lang-config">LuaHookMapToStorage /path/to/lua/script.lua check_cache</pre>
321
322     <pre class="prettyprint lang-lua">require"apache2"
323 cached_files = {}
324
325 function read_file(filename) 
326     local input = io.open(filename, "r")
327     if input then
328         local data = input:read("*a")
329         cached_files[filename] = data
330         file = cached_files[filename]
331         input:close()
332     end
333     return cached_files[filename]
334 end
335
336 function check_cache(r)
337     if r.filename:match("%.png$") then -- Only match PNG files
338         local file = cached_files[r.filename] -- Check cache entries
339         if not file then
340             file = read_file(r.filename)  -- Read file into cache
341         end
342         if file then -- If file exists, write it out
343             r.status = 200
344             r:write(file)
345             r:info(("Sent %s to client from cache"):format(r.filename))
346             return apache2.DONE -- skip default handler for PNG files
347         end
348     end
349     return apache2.DECLINED -- If we had nothing to do, let others serve this.
350 end</pre>
351
352
353     
354 </div>
355 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
356 <div class="directive-section"><h2><a name="LuaHookTranslateName" id="LuaHookTranslateName">LuaHookTranslateName</a> <a name="luahooktranslatename" id="luahooktranslatename">Directive</a></h2>
357 <table class="directive">
358 <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>
359 <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>
360 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
361 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
362 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
363 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
364 <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>
365 </table><p>
366     Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
367     request processing. The hook function receives a single
368     argument, the request_rec, and should return a status code,
369     which is either an HTTP error code, or the constants defined
370     in the apache2 module: apache2.OK, apache2.DECLINED, or
371     apache2.DONE. </p>
372
373     <p>For those new to hooks, basically each hook will be invoked
374     until one of them returns apache2.OK. If your hook doesn't
375     want to do the translation it should just return
376     apache2.DECLINED. If the request should stop processing, then
377     return apache2.DONE.</p>
378
379     <p>Example:</p>
380
381 <pre class="prettyprint lang-config"># httpd.conf
382 LuaHookTranslateName /scripts/conf/hooks.lua silly_mapper</pre>
383
384
385 <pre class="prettyprint lang-lua">-- /scripts/conf/hooks.lua --
386 require "apache2"
387 function silly_mapper(r)
388     if r.uri == "/" then
389         r.filename = "/var/www/home.lua"
390         return apache2.OK
391     else
392         return apache2.DECLINED
393     end
394 end</pre>
395
396
397    <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
398    context.</p></div>
399
400    <div class="note"><h3>Ordering</h3><p>The optional arguments "early" or "late" 
401    control when this script runs relative to other modules.</p></div>
402
403
404 </div>
405 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
406 <div class="directive-section"><h2><a name="LuaHookTypeChecker" id="LuaHookTypeChecker">LuaHookTypeChecker</a> <a name="luahooktypechecker" id="luahooktypechecker">Directive</a></h2>
407 <table class="directive">
408 <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>
409 <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>
410 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
411 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
412 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
413 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
414 </table><p>
415     This directive provides a hook for the type_checker phase of the request processing. 
416     This phase is where requests are assigned a content type and a handler, and thus can 
417     be used to modify the type and handler based on input:
418     </p>
419     <pre class="prettyprint lang-config">LuaHookTypeChecker /path/to/lua/script.lua type_checker</pre>
420
421     <pre class="prettyprint lang-lua">    function type_checker(r)
422         if r.uri:match("%.to_gif$") then -- match foo.png.to_gif
423             r.content_type = "image/gif" -- assign it the image/gif type
424             r.handler = "gifWizard"      -- tell the gifWizard module to handle this
425             r.filename = r.uri:gsub("%.to_gif$", "") -- fix the filename requested
426             return apache2.OK
427         end
428
429         return apache2.DECLINED
430     end</pre>
431
432
433 </div>
434 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
435 <div class="directive-section"><h2><a name="LuaInherit" id="LuaInherit">LuaInherit</a> <a name="luainherit" id="luainherit">Directive</a></h2>
436 <table class="directive">
437 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Controls how parent configuration sections are merged into children</td></tr>
438 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaInherit none|parent-first|parent-last</code></td></tr>
439 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaInherit parent-first</code></td></tr>
440 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
441 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
442 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
443 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
444 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.4.0 and later</td></tr>
445 </table><p>By default, if LuaHook* directives are used in overlapping
446     Directory or Location configuration sections, the scripts defined in the
447     more specific section are run <em>after</em> those defined in the more
448     generic section (LuaInherit parent-first).  You can reverse this order, or
449     make the parent context not apply at all.</p>
450     
451     <p> In previous 2.3.x releases, the default was effectively to ignore LuaHook*
452     directives from parent configuration sections.</p>
453 </div>
454 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
455 <div class="directive-section"><h2><a name="LuaInputFilter" id="LuaInputFilter">LuaInputFilter</a> <a name="luainputfilter" id="luainputfilter">Directive</a></h2>
456 <table class="directive">
457 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a Lua function for content input filtering</td></tr>
458 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaInputFilter filter_name /path/to/lua/script.lua function_name</code></td></tr>
459 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
460 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
461 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
462 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.4.5 and later</td></tr>
463 </table>
464 <p>Provides a means of adding a Lua function as an input filter. 
465 As with output filters, input filters work as coroutines, 
466 first yielding before buffers are sent, then yielding whenever 
467 a bucket needs to be passed down the chain, and finally (optionally) 
468 yielding anything that needs to be appended to the input data. The 
469 global variable <code>bucket</code> holds the buckets as they are passed 
470 onto the Lua script:
471 </p>
472
473 <pre class="prettyprint lang-config">LuaInputFilter myInputFilter /www/filter.lua input_filter
474 &lt;Files *.lua&gt;
475   SetInputFilter myInputFilter
476 &lt;/Files&gt;</pre>
477
478 <pre class="prettyprint lang-lua">--[[
479     Example input filter that converts all POST data to uppercase.
480 ]]--
481 function input_filter(r)
482     print("luaInputFilter called") -- debug print
483     coroutine.yield() -- Yield and wait for buckets
484     while bucket do -- For each bucket, do...
485         local output = string.upper(bucket) -- Convert all POST data to uppercase
486         coroutine.yield(output) -- Send converted data down the chain
487     end
488     -- No more buckets available.
489     coroutine.yield("&amp;filterSignature=1234") -- Append signature at the end
490 end</pre>
491
492 <p>
493 The input filter supports denying/skipping a filter if it is deemed unwanted:
494 </p>
495 <pre class="prettyprint lang-lua">function input_filter(r)
496     if not good then
497         return -- Simply deny filtering, passing on the original content instead
498     end
499     coroutine.yield() -- wait for buckets
500     ... -- insert filter stuff here
501 end</pre>
502
503 <p>
504 See "<a href="#modifying_buckets">Modifying contents with Lua 
505 filters</a>" for more information.
506 </p>
507
508 </div>
509 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
510 <div class="directive-section"><h2><a name="LuaMapHandler" id="LuaMapHandler">LuaMapHandler</a> <a name="luamaphandler" id="luamaphandler">Directive</a></h2>
511 <table class="directive">
512 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Map a path to a lua handler</td></tr>
513 <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>
514 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
515 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
516 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
517 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
518 </table>
519     <p>This directive matches a uri pattern to invoke a specific
520     handler function in a specific file. It uses PCRE regular
521     expressions to match the uri, and supports interpolating
522     match groups into both the file path and the function name. 
523     Be careful writing your regular expressions to avoid security
524     issues.</p>
525    <div class="example"><h3>Examples:</h3><pre class="prettyprint lang-config">LuaMapHandler /(\w+)/(\w+) /scripts/$1.lua handle_$2</pre>
526 </div>
527         <p>This would match uri's such as /photos/show?id=9
528         to the file /scripts/photos.lua and invoke the
529         handler function handle_show on the lua vm after
530         loading that file.</p>
531
532 <pre class="prettyprint lang-config">LuaMapHandler /bingo /scripts/wombat.lua</pre>
533
534         <p>This would invoke the "handle" function, which
535         is the default if no specific function name is
536         provided.</p>
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="LuaOutputFilter" id="LuaOutputFilter">LuaOutputFilter</a> <a name="luaoutputfilter" id="luaoutputfilter">Directive</a></h2>
541 <table class="directive">
542 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a Lua function for content output filtering</td></tr>
543 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaOutputFilter filter_name /path/to/lua/script.lua function_name</code></td></tr>
544 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config</td></tr>
545 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
546 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
547 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>2.4.5 and later</td></tr>
548 </table>
549 <p>Provides a means of adding a Lua function as an output filter. 
550 As with input filters, output filters work as coroutines, 
551 first yielding before buffers are sent, then yielding whenever 
552 a bucket needs to be passed down the chain, and finally (optionally) 
553 yielding anything that needs to be appended to the input data. The 
554 global variable <code>bucket</code> holds the buckets as they are passed 
555 onto the Lua script:
556 </p>
557
558 <pre class="prettyprint lang-config">LuaOutputFilter myOutputFilter /www/filter.lua output_filter
559 &lt;Files *.lua&gt;
560   SetOutputFilter myOutputFilter
561 &lt;/Files&gt;</pre>
562
563 <pre class="prettyprint lang-lua">--[[
564     Example output filter that escapes all HTML entities in the output
565 ]]--
566 function output_filter(r)
567     coroutine.yield("(Handled by myOutputFilter)&lt;br/&gt;\n") -- Prepend some data to the output,
568                                                           -- yield and wait for buckets.
569     while bucket do -- For each bucket, do...
570         local output = r:escape_html(bucket) -- Escape all output
571         coroutine.yield(output) -- Send converted data down the chain
572     end
573     -- No more buckets available.
574 end</pre>
575
576 <p>
577 As with the input filter, the output filter supports denying/skipping a filter 
578 if it is deemed unwanted:
579 </p>
580 <pre class="prettyprint lang-lua">function output_filter(r)
581     if not r.content_type:match("text/html") then
582         return -- Simply deny filtering, passing on the original content instead
583     end
584     coroutine.yield() -- wait for buckets
585     ... -- insert filter stuff here
586 end</pre>
587
588 <div class="note"><h3>Lua filters with <code class="module"><a href="../mod/mod_filter.html">mod_filter</a></code></h3>
589 <p> When a Lua filter is used as the underlying provider via the 
590 <code class="directive"><a href="../mod/mod_filter.html#filterprovider">FilterProvider</a></code> directive, filtering 
591 will only work when the <var>filter-name</var> is identical to the <var>provider-name</var>.
592 </p> </div>
593
594 <p>
595 See "<a href="#modifying_buckets">Modifying contents with Lua filters</a>" for more 
596 information.
597 </p>
598
599
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="LuaPackageCPath" id="LuaPackageCPath">LuaPackageCPath</a> <a name="luapackagecpath" id="luapackagecpath">Directive</a></h2>
603 <table class="directive">
604 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.cpath</td></tr>
605 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackageCPath /path/to/include/?.soa</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>Add a path to lua's shared library search path. Follows the same
612     conventions as lua. This just munges the package.cpath in the
613     lua vms.</p>
614
615
616 </div>
617 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
618 <div class="directive-section"><h2><a name="LuaPackagePath" id="LuaPackagePath">LuaPackagePath</a> <a name="luapackagepath" id="luapackagepath">Directive</a></h2>
619 <table class="directive">
620 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Add a directory to lua's package.path</td></tr>
621 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaPackagePath /path/to/include/?.lua</code></td></tr>
622 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
623 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
624 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
625 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
626 </table><p>Add a path to lua's module search path. Follows the same
627     conventions as lua. This just munges the package.path in the
628     lua vms.</p>
629
630     <div class="example"><h3>Examples:</h3><pre class="prettyprint lang-config">LuaPackagePath /scripts/lib/?.lua
631 LuaPackagePath /scripts/lib/?/init.lua</pre>
632 </div>
633
634 </div>
635 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
636 <div class="directive-section"><h2><a name="LuaQuickHandler" id="LuaQuickHandler">LuaQuickHandler</a> <a name="luaquickhandler" id="luaquickhandler">Directive</a></h2>
637 <table class="directive">
638 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Provide a hook for the quick handler of request processing</td></tr>
639 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaQuickHandler /path/to/script.lua hook_function_name</code></td></tr>
640 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
641 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
642 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
643 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
644 </table>
645     <p>
646     This phase is run immediately after the request has been mapped to a virtal host, 
647     and can be used to either do some request processing before the other phases kick 
648     in, or to serve a request without the need to translate, map to storage et cetera. 
649     As this phase is run before anything else, directives such as <code class="directive"><a href="../mod/core.html#location">&lt;Location&gt;</a></code> or <code class="directive"><a href="../mod/core.html#directory">&lt;Directory&gt;</a></code> are void in this phase, just as 
650     URIs have not been properly parsed yet.
651     </p>
652    <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
653    context.</p></div>
654
655 </div>
656 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
657 <div class="directive-section"><h2><a name="LuaRoot" id="LuaRoot">LuaRoot</a> <a name="luaroot" id="luaroot">Directive</a></h2>
658 <table class="directive">
659 <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>
660 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaRoot /path/to/a/directory</code></td></tr>
661 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
662 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
663 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
664 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
665 </table>
666     <p>Specify the base path which will be used to evaluate all
667     relative paths within mod_lua. If not specified they
668     will be resolved relative to the current working directory,
669     which may not always work well for a server.</p>
670
671 </div>
672 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
673 <div class="directive-section"><h2><a name="LuaScope" id="LuaScope">LuaScope</a> <a name="luascope" id="luascope">Directive</a></h2>
674 <table class="directive">
675 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>One of once, request, conn, thread -- default is once</td></tr>
676 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>LuaScope once|request|conn|thread|server [min] [max]</code></td></tr>
677 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>LuaScope once</code></td></tr>
678 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
679 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>All</td></tr>
680 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Experimental</td></tr>
681 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_lua</td></tr>
682 </table>
683     <p>Specify the life cycle scope of the Lua interpreter which will
684     be used by handlers in this "Directory." The default is "once"</p>
685
686    <dl>
687     <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
688
689     <dt>request:</dt> <dd>use the interpreter to handle anything based on
690              the same file within this request, which is also
691              request scoped.</dd>
692
693     <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
694
695     <dt>thread:</dt> <dd>Use the interpreter for the lifetime of the thread 
696             handling the request (only available with threaded MPMs).</dd>
697
698     <dt>server:</dt>  <dd>This one is different than others because the
699             server scope is quite long lived, and multiple threads
700             will have the same server_rec. To accommodate this,
701             server scoped Lua states are stored in an apr
702             resource list. The <code>min</code> and <code>max</code> arguments 
703             specify the minimum and maximum number of Lua states to keep in the 
704             pool.</dd>
705    </dl>
706     <p>
707     Generally speaking, the <code>thread</code> and <code>server</code> scopes 
708     execute roughly 2-3 times faster than the rest, because they don't have to 
709     spawn new Lua states on every request (especially with the event MPM, as 
710     even keepalive requests will use a new thread for each request). If you are 
711     satisfied that your scripts will not have problems reusing a state, then 
712     the <code>thread</code> or <code>server</code> scopes should be used for 
713     maximum performance. While the <code>thread</code> scope will provide the 
714     fastest responses, the <code>server</code> scope will use less memory, as 
715     states are pooled, allowing f.x. 1000 threads to share only 100 Lua states, 
716     thus using only 10% of the memory required by the <code>thread</code> scope.
717     </p>
718
719 </div>
720 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
721 <div class="section">
722 <h2><a name="basicconf" id="basicconf">Basic Configuration</a></h2>
723
724 <p>The basic module loading directive is</p>
725
726 <pre class="prettyprint lang-config">LoadModule lua_module modules/mod_lua.so</pre>
727
728
729 <p>
730 <code>mod_lua</code> provides a handler named <code>lua-script</code>,
731 which can be used with a <code class="directive"><a href="../mod/core.html#sethandler">SetHandler</a></code> or
732 <code class="directive"><a href="../mod/mod_mime.html#addhandler">AddHandler</a></code> directive:</p>
733
734 <pre class="prettyprint lang-config">&lt;Files *.lua&gt;
735     SetHandler lua-script
736 &lt;/Files&gt;</pre>
737
738
739 <p>
740 This will cause <code>mod_lua</code> to handle requests for files
741 ending in <code>.lua</code> by invoking that file's
742 <code>handle</code> function.
743 </p>
744
745 <p>For more flexibility, see <code class="directive">LuaMapHandler</code>.
746 </p>
747
748 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
749 <div class="section">
750 <h2><a name="writinghandlers" id="writinghandlers">Writing Handlers</a></h2>
751 <p> In the Apache HTTP Server API, the handler is a specific kind of hook
752 responsible for generating the response.  Examples of modules that include a
753 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>,
754 and <code class="module"><a href="../mod/mod_status.html">mod_status</a></code>.</p>
755
756 <p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
757 just evaluating a script body CGI style. A handler function looks
758 something like this:</p>
759
760
761 <pre class="prettyprint lang-lua">
762 <strong>example.lua</strong><br />
763 -- example handler
764
765 require "string"
766
767 --[[
768      This is the default method name for Lua handlers, see the optional
769      function-name in the LuaMapHandler directive to choose a different
770      entry point.
771 --]]
772 function handle(r)
773     r.content_type = "text/plain"
774
775     if r.method == 'GET' then
776         r:puts("Hello Lua World!\n")
777         for k, v in pairs( r:parseargs() ) do
778             r:puts( string.format("%s: %s\n", k, v) )
779         end
780     elseif r.method == 'POST' then
781         r:puts("Hello Lua World!\n")
782         for k, v in pairs( r:parsebody() ) do
783             r:puts( string.format("%s: %s\n", k, v) )
784         end
785     elseif r.method == 'PUT' then
786 -- use our own Error contents
787         r:puts("Unsupported HTTP method " .. r.method)
788         r.status = 405
789         return apache2.ok
790     else
791 -- use the ErrorDocument
792         return 501
793     end
794     return apache2.OK
795 end</pre>
796
797
798 <p>
799 This handler function just prints out the uri or form encoded
800 arguments to a plaintext page.
801 </p>
802
803 <p>
804 This means (and in fact encourages) that you can have multiple
805 handlers (or hooks, or filters) in the same script.
806 </p>
807
808 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
809 <div class="section">
810 <h2><a name="writingauthzproviders" id="writingauthzproviders">Writing Authorization Providers</a></h2>
811
812
813 <p><code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code> provides a high-level interface to
814 authorization that is much easier to use than using into the relevant
815 hooks directly. The first argument to the
816 <code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code> directive gives
817 the name of the responsible authorization provider. For any
818 <code class="directive"><a href="../mod/mod_authz_core.html#require">Require</a></code> line,
819 <code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code> will call the authorization provider
820 of the given name, passing the rest of the line as parameters. The
821 provider will then check authorization and pass the result as return
822 value.</p>
823
824 <p>The authz provider is normally called before authentication. If it needs to
825 know the authenticated user name (or if the user will be authenticated at
826 all), the provider must return <code>apache2.AUTHZ_DENIED_NO_USER</code>.
827 This will cause authentication to proceed and the authz provider to be
828 called a second time.</p>
829
830 <p>The following authz provider function takes two arguments, one ip
831 address and one user name. It will allow access from the given ip address
832 without authentication, or if the authenticated user matches the second
833 argument:</p>
834
835 <pre class="prettyprint lang-lua">
836 <strong>authz_provider.lua</strong><br />
837
838 require 'apache2'
839
840 function authz_check_foo(r, ip, user)
841     if r.useragent_ip == ip then
842         return apache2.AUTHZ_GRANTED
843     elseif r.user == nil then
844         return apache2.AUTHZ_DENIED_NO_USER
845     elseif r.user == user then
846         return apache2.AUTHZ_GRANTED
847     else
848         return apache2.AUTHZ_DENIED
849     end
850 end</pre>
851
852
853 <p>The following configuration registers this function as provider
854 <code>foo</code> and configures it for URL <code>/</code>:</p>
855 <pre class="prettyprint lang-config">LuaAuthzProvider foo authz_provider.lua authz_check_foo
856 &lt;Location /&gt;
857   Require foo 10.1.2.3 john_doe
858 &lt;/Location&gt;</pre>
859
860
861 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
862 <div class="section">
863 <h2><a name="writinghooks" id="writinghooks">Writing Hooks</a></h2>
864
865 <p>Hook functions are how modules (and Lua scripts) participate in the
866 processing of requests. Each type of hook exposed by the server exists for
867 a specific purpose, such as mapping requests to the file system,
868 performing access control, or setting mime types:</p>
869
870 <table class="bordered"><tr class="header">
871         <th>Hook phase</th>
872         <th>mod_lua directive</th>
873         <th>Description</th>
874     </tr>
875 <tr>
876         <td>Quick handler</td>
877         <td><code class="directive"><a href="#luaquickhandler">LuaQuickHandler</a></code></td>
878         <td>This is the first hook that will be called after a request has 
879             been mapped to a host or virtual host</td>
880     </tr>
881 <tr class="odd">
882         <td>Translate name</td>
883         <td><code class="directive"><a href="#luahooktranslatename">LuaHookTranslateName</a></code></td>
884         <td>This phase translates the requested URI into a filename on the 
885             system. Modules such as <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> and
886             <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> operate in this phase.</td>
887     </tr>
888 <tr>
889         <td>Map to storage</td>
890         <td><code class="directive"><a href="#luahookmaptostorage">LuaHookMapToStorage</a></code></td>
891         <td>This phase maps files to their physical, cached or external/proxied storage. 
892             It can be used by proxy or caching modules</td>
893     </tr>
894 <tr class="odd">
895         <td>Check Access</td>
896         <td><code class="directive"><a href="#luahookaccesschecker">LuaHookAccessChecker</a></code></td>
897         <td>This phase checks whether a client has access to a resource. This 
898             phase is run before the user is authenticated, so beware.
899         </td>
900     </tr>
901 <tr>
902         <td>Check User ID</td>
903         <td><code class="directive"><a href="#luahookcheckuserid">LuaHookCheckUserID</a></code></td>
904         <td>This phase it used to check the negotiated user ID</td>
905     </tr>
906 <tr class="odd">
907         <td>Check Authorization</td>
908         <td><code class="directive"><a href="#luahookauthchecker">LuaHookAuthChecker</a></code> or 
909             <code class="directive"><a href="#luaauthzprovider">LuaAuthzProvider</a></code></td>
910         <td>This phase authorizes a user based on the negotiated credentials, such as 
911             user ID, client certificate etc.
912         </td>
913     </tr>
914 <tr>
915         <td>Check Type</td>
916         <td><code class="directive"><a href="#luahooktypechecker">LuaHookTypeChecker</a></code></td>
917         <td>This phase checks the requested file and assigns a content type and 
918             a handler to it</td>
919     </tr>
920 <tr class="odd">
921         <td>Fixups</td>
922         <td><code class="directive"><a href="#luahookfixups">LuaHookFixups</a></code></td>
923         <td>This is the final "fix anything" phase before the content handlers 
924             are run. Any last-minute changes to the request should be made here.</td>
925     </tr>
926 <tr>
927         <td>Content handler</td>
928         <td>fx. <code>.lua</code> files or through <code class="directive"><a href="#luamaphandler">LuaMapHandler</a></code></td>
929         <td>This is where the content is handled. Files are read, parsed, some are run, 
930             and the result is sent to the client</td>
931     </tr>
932 <tr class="odd">
933         <td>Logging</td>
934         <td><code class="directive"><a href="#luahooklog">LuaHookLog</a></code></td>
935         <td>Once a request has been handled, it enters several logging phases, 
936             which logs the request in either the error or access log. Mod_lua
937             is able to hook into the start of this and control logging output.</td>
938     </tr>
939 </table>
940
941 <p>Hook functions are passed the request object as their only argument 
942 (except for LuaAuthzProvider, which also gets passed the arguments from 
943 the Require directive).
944 They can return any value, depending on the hook, but most commonly
945 they'll return OK, DONE, or DECLINED, which you can write in Lua as
946 <code>apache2.OK</code>, <code>apache2.DONE</code>, or
947 <code>apache2.DECLINED</code>, or else an HTTP status code.</p>
948
949
950 <pre class="prettyprint lang-lua">
951 <strong>translate_name.lua</strong><br />
952 -- example hook that rewrites the URI to a filesystem path.
953
954 require 'apache2'
955
956 function translate_name(r)
957     if r.uri == "/translate-name" then
958         r.filename = r.document_root .. "/find_me.txt"
959         return apache2.OK
960     end
961     -- we don't care about this URL, give another module a chance
962     return apache2.DECLINED
963 end</pre>
964
965
966
967 <pre class="prettyprint lang-lua">
968 <strong>translate_name2.lua</strong><br />
969 --[[ example hook that rewrites one URI to another URI. It returns a
970      apache2.DECLINED to give other URL mappers a chance to work on the
971      substitution, including the core translate_name hook which maps based
972      on the DocumentRoot.
973
974      Note: Use the early/late flags in the directive to make it run before
975            or after mod_alias.
976 --]]
977
978 require 'apache2'
979
980 function translate_name(r)
981     if r.uri == "/translate-name" then
982         r.uri = "/find_me.txt"
983         return apache2.DECLINED
984     end
985     return apache2.DECLINED
986 end</pre>
987
988 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
989 <div class="section">
990 <h2><a name="datastructures" id="datastructures">Data Structures</a></h2>
991
992 <dl>
993 <dt>request_rec</dt>
994         <dd>
995         <p>The request_rec is mapped in as a userdata. It has a metatable
996         which lets you do useful things with it. For the most part it
997         has the same fields as the request_rec struct, many of which are writable as
998         well as readable.  (The table fields' content can be changed, but the
999         fields themselves cannot be set to different tables.)</p>
1000
1001         <table class="bordered"><tr class="header">
1002           <th><strong>Name</strong></th>
1003           <th><strong>Lua type</strong></th>
1004           <th><strong>Writable</strong></th>
1005           <th><strong>Description</strong></th>
1006         </tr>
1007 <tr>
1008           <td><code>allowoverrides</code></td>
1009           <td>string</td>
1010           <td>no</td>
1011           <td>The AllowOverride options applied to the current request.</td>
1012         </tr>
1013 <tr class="odd">
1014           <td><code>ap_auth_type</code></td>
1015           <td>string</td>
1016           <td>no</td>
1017           <td>If an authentication check was made, this is set to the type 
1018           of authentication (f.x. <code>basic</code>)</td>
1019         </tr>
1020 <tr>
1021           <td><code>args</code></td>
1022           <td>string</td>
1023           <td>yes</td>
1024           <td>The query string arguments extracted from the request 
1025             (f.x. <code>foo=bar&amp;name=johnsmith</code>)</td>
1026         </tr>
1027 <tr class="odd">
1028           <td><code>assbackwards</code></td>
1029           <td>boolean</td>
1030           <td>no</td>
1031           <td>Set to true if this is an HTTP/0.9 style request 
1032             (e.g. <code>GET /foo</code> (with no headers) )</td>
1033         </tr>
1034 <tr>
1035           <td><code>auth_name</code></td>
1036           <td>string</td>
1037           <td>no</td>
1038           <td>The realm name used for authorization (if applicable).</td>
1039         </tr>
1040 <tr class="odd">
1041           <td><code>banner</code></td>
1042           <td>string</td>
1043           <td>no</td>
1044           <td>The server banner, f.x. <code>Apache HTTP Server/2.4.3 openssl/0.9.8c</code></td>
1045         </tr>
1046 <tr>
1047           <td><code>basic_auth_pw</code></td>
1048           <td>string</td>
1049           <td>no</td>
1050           <td>The basic auth password sent with this request, if any</td>
1051         </tr>
1052 <tr class="odd">
1053           <td><code>canonical_filename</code></td>
1054           <td>string</td>
1055           <td>no</td>
1056           <td>The canonical filename of the request</td>
1057         </tr>
1058 <tr>
1059           <td><code>content_encoding</code></td>
1060           <td>string</td>
1061           <td>no</td>
1062           <td>The content encoding of the current request</td>
1063         </tr>
1064 <tr class="odd">
1065           <td><code>content_type</code></td>
1066           <td>string</td>
1067           <td>yes</td>
1068           <td>The content type of the current request, as determined in the 
1069             type_check phase (f.x. <code>image/gif</code> or <code>text/html</code>)</td>
1070         </tr>
1071 <tr>
1072           <td><code>context_prefix</code></td>
1073           <td>string</td>
1074           <td>no</td>
1075           <td />
1076         </tr>
1077 <tr class="odd">
1078           <td><code>context_document_root</code></td>
1079           <td>string</td>
1080           <td>no</td>
1081           <td />
1082         </tr>
1083 <tr>
1084           <td><code>document_root</code></td>
1085           <td>string</td>
1086           <td>no</td>
1087           <td>The document root of the host</td>
1088         </tr>
1089 <tr class="odd">
1090           <td><code>err_headers_out</code></td>
1091           <td>table</td>
1092           <td>no</td>
1093           <td>MIME header environment for the response, printed even on errors and
1094             persist across internal redirects</td>
1095         </tr>
1096 <tr>
1097           <td><code>filename</code></td>
1098           <td>string</td>
1099           <td>yes</td>
1100           <td>The file name that the request maps to, f.x. /www/example.com/foo.txt. This can be 
1101             changed in the translate-name or map-to-storage phases of a request to allow the 
1102             default handler (or script handlers) to serve a different file than what was requested.</td>
1103         </tr>
1104 <tr class="odd">
1105           <td><code>handler</code></td>
1106           <td>string</td>
1107           <td>yes</td>
1108           <td>The name of the <a href="../handler.html">handler</a> that should serve this request, f.x. 
1109             <code>lua-script</code> if it is to be served by mod_lua. This is typically set by the 
1110             <code class="directive"><a href="../mod/mod_mime.html#addhandler">AddHandler</a></code> or <code class="directive"><a href="../mod/core.html#sethandler">SetHandler</a></code> 
1111             directives, but could also be set via mod_lua to allow another handler to serve up a specific request 
1112             that would otherwise not be served by it.
1113             </td>
1114         </tr>
1115 <tr>
1116           <td><code>headers_in</code></td>
1117           <td>table</td>
1118           <td>yes</td>
1119           <td>MIME header environment from the request. This contains headers such as <code>Host, 
1120             User-Agent, Referer</code> and so on.</td>
1121         </tr>
1122 <tr class="odd">
1123           <td><code>headers_out</code></td>
1124           <td>table</td>
1125           <td>yes</td>
1126           <td>MIME header environment for the response.</td>
1127         </tr>
1128 <tr>
1129           <td><code>hostname</code></td>
1130           <td>string</td>
1131           <td>no</td>
1132           <td>The host name, as set by the <code>Host:</code> header or by a full URI.</td>
1133         </tr>
1134 <tr class="odd">
1135           <td><code>is_https</code></td>
1136           <td>boolean</td>
1137           <td>no</td>
1138           <td>Whether or not this request is done via HTTPS</td>
1139         </tr>
1140 <tr>
1141           <td><code>is_initial_req</code></td>
1142           <td>boolean</td>
1143           <td>no</td>
1144           <td>Whether this request is the initial request or a sub-request</td>
1145         </tr>
1146 <tr class="odd">
1147           <td><code>limit_req_body</code></td>
1148           <td>number</td>
1149           <td>no</td>
1150           <td>The size limit of the request body for this request, or 0 if no limit.</td>
1151         </tr>
1152 <tr>
1153           <td><code>log_id</code></td>
1154           <td>string</td>
1155           <td>no</td>
1156           <td>The ID to identify request in access and error log.</td>
1157         </tr>
1158 <tr class="odd">
1159           <td><code>method</code></td>
1160           <td>string</td>
1161           <td>no</td>
1162           <td>The request method, f.x. <code>GET</code> or <code>POST</code>.</td>
1163         </tr>
1164 <tr>
1165           <td><code>notes</code></td>
1166           <td>table</td>
1167           <td>yes</td>
1168           <td>A list of notes that can be passed on from one module to another.</td>
1169         </tr>
1170 <tr class="odd">
1171           <td><code>options</code></td>
1172           <td>string</td>
1173           <td>no</td>
1174           <td>The Options directive applied to the current request.</td>
1175         </tr>
1176 <tr>
1177           <td><code>path_info</code></td>
1178           <td>string</td>
1179           <td>no</td>
1180           <td>The PATH_INFO extracted from this request.</td>
1181         </tr>
1182 <tr class="odd">
1183           <td><code>port</code></td>
1184           <td>number</td>
1185           <td>no</td>
1186           <td>The server port used by the request.</td>
1187         </tr>
1188 <tr>
1189           <td><code>protocol</code></td>
1190           <td>string</td>
1191           <td>no</td>
1192           <td>The protocol used, f.x. <code>HTTP/1.1</code></td>
1193         </tr>
1194 <tr class="odd">
1195           <td><code>proxyreq</code></td>
1196           <td>string</td>
1197           <td>yes</td>
1198           <td>Denotes whether this is a proxy request or not. This value is generally set in 
1199             the post_read_request/translate_name phase of a request.</td>
1200         </tr>
1201 <tr>
1202           <td><code>range</code></td>
1203           <td>string</td>
1204           <td>no</td>
1205           <td>The contents of the <code>Range:</code> header.</td>
1206         </tr>
1207 <tr class="odd">
1208           <td><code>remaining</code></td>
1209           <td>number</td>
1210           <td>no</td>
1211           <td>The number of bytes remaining to be read from the request body.</td>
1212         </tr>
1213 <tr>
1214           <td><code>server_built</code></td>
1215           <td>string</td>
1216           <td>no</td>
1217           <td>The time the server executable was built.</td>
1218         </tr>
1219 <tr class="odd">
1220           <td><code>server_name</code></td>
1221           <td>string</td>
1222           <td>no</td>
1223           <td>The server name for this request.</td>
1224         </tr>
1225 <tr>
1226           <td><code>some_auth_required</code></td>
1227           <td>boolean</td>
1228           <td>no</td>
1229           <td>Whether some authorization is/was required for this request.</td>
1230         </tr>
1231 <tr class="odd">
1232           <td><code>subprocess_env</code></td>
1233           <td>table</td>
1234           <td>yes</td>
1235           <td>The environment variables set for this request.</td>
1236         </tr>
1237 <tr>
1238           <td><code>started</code></td>
1239           <td>number</td>
1240           <td>no</td>
1241           <td>The time the server was (re)started, in seconds since the epoch (Jan 1st, 1970)</td>
1242         </tr>
1243 <tr class="odd">
1244           <td><code>status</code></td>
1245           <td>number</td>
1246           <td>yes</td>
1247           <td>The (current) HTTP return code for this request, f.x. <code>200</code> or <code>404</code>.</td>
1248         </tr>
1249 <tr>
1250           <td><code>the_request</code></td>
1251           <td>string</td>
1252           <td>no</td>
1253           <td>The request string as sent by the client, f.x. <code>GET /foo/bar HTTP/1.1</code>.</td>
1254         </tr>
1255 <tr class="odd">
1256           <td><code>unparsed_uri</code></td>
1257           <td>string</td>
1258           <td>no</td>
1259           <td>The unparsed URI of the request</td>
1260         </tr>
1261 <tr>
1262           <td><code>uri</code></td>
1263           <td>string</td>
1264           <td>yes</td>
1265           <td>The URI after it has been parsed by httpd</td>
1266         </tr>
1267 <tr class="odd">
1268           <td><code>user</code></td>
1269           <td>string</td>
1270           <td>yes</td>
1271           <td>If an authentication check has been made, this is set to the name of the authenticated user.</td>
1272         </tr>
1273 <tr>
1274           <td><code>useragent_ip</code></td>
1275           <td>string</td>
1276           <td>no</td>
1277           <td>The IP of the user agent making the request</td>
1278         </tr>
1279 </table>
1280            </dd>
1281     </dl>
1282 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1283 <div class="section">
1284 <h2><a name="functions" id="functions">Built in functions</a></h2>
1285
1286 <p>The request_rec object has (at least) the following methods:</p>
1287
1288 <pre class="prettyprint lang-lua">r:flush()   -- flushes the output buffer.
1289             -- Returns true if the flush was successful, false otherwise.
1290
1291 while we_have_stuff_to_send do
1292     r:puts("Bla bla bla\n") -- print something to client
1293     r:flush() -- flush the buffer (send to client)
1294     r.usleep(500000) -- fake processing time for 0.5 sec. and repeat
1295 end</pre>
1296
1297
1298 <pre class="prettyprint lang-lua">r:addoutputfilter(name|function) -- add an output filter:
1299
1300 r:addoutputfilter("fooFilter") -- add the fooFilter to the output stream</pre>
1301
1302
1303 <pre class="prettyprint lang-lua">r:sendfile(filename) -- sends an entire file to the client, using sendfile if supported by the current platform:
1304
1305 if use_sendfile_thing then
1306     r:sendfile("/var/www/large_file.img")
1307 end</pre>
1308
1309
1310 <pre class="prettyprint lang-lua">r:parseargs() -- returns two tables; one standard key/value table for regular GET data, 
1311               -- and one for multi-value data (fx. foo=1&amp;foo=2&amp;foo=3):
1312
1313 local GET, GETMULTI = r:parseargs()
1314 r:puts("Your name is: " .. GET['name'] or "Unknown")</pre>
1315
1316
1317 <pre class="prettyprint lang-lua">r:parsebody([sizeLimit]) -- parse the request body as a POST and return two lua tables,
1318                          -- just like r:parseargs().
1319                          -- An optional number may be passed to specify the maximum number 
1320                          -- of bytes to parse. Default is 8192 bytes:
1321                  
1322 local POST, POSTMULTI = r:parsebody(1024*1024)
1323 r:puts("Your name is: " .. POST['name'] or "Unknown")</pre>
1324
1325
1326 <pre class="prettyprint lang-lua">r:puts("hello", " world", "!") -- print to response body, self explanatory</pre>
1327
1328
1329 <pre class="prettyprint lang-lua">r:write("a single string") -- print to response body, self explanatory</pre>
1330
1331
1332 <pre class="prettyprint lang-lua">r:escape_html("&lt;html&gt;test&lt;/html&gt;") -- Escapes HTML code and returns the escaped result</pre>
1333
1334
1335 <pre class="prettyprint lang-lua">r:base64_encode(string) -- Encodes a string using the Base64 encoding standard:
1336
1337 local encoded = r:base64_encode("This is a test") -- returns VGhpcyBpcyBhIHRlc3Q=</pre>
1338
1339
1340 <pre class="prettyprint lang-lua">r:base64_decode(string) -- Decodes a Base64-encoded string:
1341
1342 local decoded = r:base64_decode("VGhpcyBpcyBhIHRlc3Q=") -- returns 'This is a test'</pre>
1343
1344
1345 <pre class="prettyprint lang-lua">r:md5(string) -- Calculates and returns the MD5 digest of a string (binary safe):
1346
1347 local hash = r:md5("This is a test") -- returns ce114e4501d2f4e2dcea3e17b546f339</pre>
1348
1349
1350 <pre class="prettyprint lang-lua">r:sha1(string) -- Calculates and returns the SHA1 digest of a string (binary safe):
1351
1352 local hash = r:sha1("This is a test") -- returns a54d88e06612d820bc3be72877c74f257b561b19</pre>
1353
1354
1355 <pre class="prettyprint lang-lua">r:escape(string) -- URL-Escapes a string:
1356
1357 local url = "http://foo.bar/1 2 3 &amp; 4 + 5"
1358 local escaped = r:escape(url) -- returns 'http%3a%2f%2ffoo.bar%2f1+2+3+%26+4+%2b+5'</pre>
1359
1360
1361 <pre class="prettyprint lang-lua">r:unescape(string) -- Unescapes an URL-escaped string:
1362
1363 local url = "http%3a%2f%2ffoo.bar%2f1+2+3+%26+4+%2b+5"
1364 local unescaped = r:unescape(url) -- returns 'http://foo.bar/1 2 3 &amp; 4 + 5'</pre>
1365
1366
1367 <pre class="prettyprint lang-lua">r:construct_url(string) -- Constructs an URL from an URI
1368
1369 local url = r:construct_url(r.uri)</pre>
1370
1371
1372 <pre class="prettyprint lang-lua">r.mpm_query(number) -- Queries the server for MPM information using ap_mpm_query:
1373
1374 local mpm = r.mpm_query(14)
1375 if mpm == 1 then
1376     r:puts("This server uses the Event MPM")
1377 end</pre>
1378
1379
1380 <pre class="prettyprint lang-lua">r:expr(string) -- Evaluates an <a href="../expr.html">expr</a> string.
1381
1382 if r:expr("%{HTTP_HOST} =~ /^www/") then
1383     r:puts("This host name starts with www")
1384 end</pre>
1385
1386
1387 <pre class="prettyprint lang-lua">r:scoreboard_process(a) -- Queries the server for information about the process at position <code>a</code>:
1388
1389 local process = r:scoreboard_process(1)
1390 r:puts("Server 1 has PID " .. process.pid)</pre>
1391
1392
1393 <pre class="prettyprint lang-lua">r:scoreboard_worker(a, b) -- Queries for information about the worker thread, <code>b</code>, in process <code>a</code>:
1394
1395 local thread = r:scoreboard_worker(1, 1)
1396 r:puts("Server 1's thread 1 has thread ID " .. thread.tid .. " and is in " .. thread.status .. " status")</pre>
1397
1398
1399
1400 <pre class="prettyprint lang-lua">r:clock() -- Returns the current time with microsecond precision</pre>
1401
1402
1403 <pre class="prettyprint lang-lua">r:requestbody(filename) -- Reads and returns the request body of a request.
1404                 -- If 'filename' is specified, it instead saves the
1405                 -- contents to that file:
1406                 
1407 local input = r:requestbody()
1408 r:puts("You sent the following request body to me:\n")
1409 r:puts(input)</pre>
1410
1411
1412 <pre class="prettyprint lang-lua">r:add_input_filter(filter_name) -- Adds 'filter_name' as an input filter</pre>
1413
1414
1415 <pre class="prettyprint lang-lua">r.module_info(module_name) -- Queries the server for information about a module
1416
1417 local mod = r.module_info("mod_lua.c")
1418 if mod then
1419     for k, v in pairs(mod.commands) do
1420        r:puts( ("%s: %s\n"):format(k,v)) -- print out all directives accepted by this module
1421     end
1422 end</pre>
1423
1424
1425 <pre class="prettyprint lang-lua">r:loaded_modules() -- Returns a list of modules loaded by httpd:
1426
1427 for k, module in pairs(r:loaded_modules()) do
1428     r:puts("I have loaded module " .. module .. "\n")
1429 end</pre>
1430
1431
1432 <pre class="prettyprint lang-lua">r:runtime_dir_relative(filename) -- Compute the name of a run-time file (e.g., shared memory "file") 
1433                          -- relative to the appropriate run-time directory.</pre>
1434
1435
1436 <pre class="prettyprint lang-lua">r:server_info() -- Returns a table containing server information, such as 
1437                 -- the name of the httpd executable file, mpm used etc.</pre>
1438
1439
1440 <pre class="prettyprint lang-lua">r:set_document_root(file_path) -- Sets the document root for the request to file_path</pre>
1441
1442
1443
1444
1445 <pre class="prettyprint lang-lua">r:set_context_info(prefix, docroot) -- Sets the context prefix and context document root for a request</pre>
1446
1447
1448 <pre class="prettyprint lang-lua">r:os_escape_path(file_path) -- Converts an OS path to a URL in an OS dependent way</pre>
1449
1450
1451 <pre class="prettyprint lang-lua">r:escape_logitem(string) -- Escapes a string for logging</pre>
1452
1453
1454 <pre class="prettyprint lang-lua">r.strcmp_match(string, pattern) -- Checks if 'string' matches 'pattern' using strcmp_match (globs).
1455                         -- fx. whether 'www.example.com' matches '*.example.com':
1456                         
1457 local match = r.strcmp_match("foobar.com", "foo*.com")
1458 if match then 
1459     r:puts("foobar.com matches foo*.com")
1460 end</pre>
1461
1462
1463 <pre class="prettyprint lang-lua">r:set_keepalive() -- Sets the keepalive status for a request. Returns true if possible, false otherwise.</pre>
1464
1465
1466 <pre class="prettyprint lang-lua">r:make_etag() -- Constructs and returns the etag for the current request.</pre>
1467
1468
1469 <pre class="prettyprint lang-lua">r:send_interim_response(clear) -- Sends an interim (1xx) response to the client.
1470                        -- if 'clear' is true, available headers will be sent and cleared.</pre>
1471
1472
1473 <pre class="prettyprint lang-lua">r:custom_response(status_code, string) -- Construct and set a custom response for a given status code.
1474                                -- This works much like the ErrorDocument directive:
1475                                
1476 r:custom_response(404, "Baleted!")</pre>
1477
1478
1479 <pre class="prettyprint lang-lua">r.exists_config_define(string) -- Checks whether a configuration definition exists or not:
1480
1481 if r.exists_config_define("FOO") then
1482     r:puts("httpd was probably run with -DFOO, or it was defined in the configuration")
1483 end</pre>
1484
1485
1486 <pre class="prettyprint lang-lua">r:state_query(string) -- Queries the server for state information</pre>
1487
1488
1489 <pre class="prettyprint lang-lua">r:stat(filename [,wanted]) -- Runs stat() on a file, and returns a table with file information:
1490
1491 local info = r:stat("/var/www/foo.txt")
1492 if info then
1493     r:puts("This file exists and was last modified at: " .. info.modified)
1494 end</pre>
1495
1496
1497 <pre class="prettyprint lang-lua">r:regex(string, pattern [,flags]) -- Runs a regular expression match on a string, returning captures if matched:
1498
1499 local matches = r:regex("foo bar baz", [[foo (\w+) (\S*)]])
1500 if matches then
1501     r:puts("The regex matched, and the last word captured ($2) was: " .. matches[2])
1502 end
1503
1504 -- Example ignoring case sensitivity:
1505 local matches = r:regex("FOO bar BAz", [[(foo) bar]], 1)
1506
1507 -- Flags can be a bitwise combination of:
1508 -- 0x01: Ignore case
1509 -- 0x02: Multiline search</pre>
1510
1511
1512 <pre class="prettyprint lang-lua">r.usleep(number_of_microseconds) -- Puts the script to sleep for a given number of microseconds.</pre>
1513
1514
1515 <pre class="prettyprint lang-lua">r:dbacquire(dbType[, dbParams]) -- Acquires a connection to a database and returns a database class.
1516                         -- See '<a href="#databases">Database connectivity</a>' for details.</pre>
1517
1518
1519 <pre class="prettyprint lang-lua">r:ivm_set("key", value) -- Set an Inter-VM variable to hold a specific value.
1520                         -- These values persist even though the VM is gone or not being used,
1521                         -- and so should only be used if MaxConnectionsPerChild is &gt; 0
1522                         -- Values can be numbers, strings and booleans, and are stored on a 
1523                         -- per process basis (so they won't do much good with a prefork mpm)
1524                         
1525 r:ivm_get("key")        -- Fetches a variable set by ivm_set. Returns the contents of the variable
1526                         -- if it exists or nil if no such variable exists.
1527                         
1528 -- An example getter/setter that saves a global variable outside the VM:
1529 function handle(r)
1530     -- First VM to call this will get no value, and will have to create it
1531     local foo = r:ivm_get("cached_data")
1532     if not foo then
1533         foo = do_some_calcs() -- fake some return value
1534         r:ivm_set("cached_data", foo) -- set it globally
1535     end
1536     r:puts("Cached data is: ", foo)
1537 end</pre>
1538
1539
1540 <pre class="prettyprint lang-lua">r:htpassword(string [,algorithm [,cost]]) -- Creates a password hash from a string.
1541                                           -- algorithm: 0 = APMD5 (default), 1 = SHA, 2 = BCRYPT, 3 = CRYPT.
1542                                           -- cost: only valid with BCRYPT algorithm (default = 5).</pre>
1543
1544
1545 <pre class="prettyprint lang-lua">r:mkdir(dir [,mode]) -- Creates a directory and sets mode to optional mode paramter.</pre>
1546
1547
1548 <pre class="prettyprint lang-lua">r:mkrdir(dir [,mode]) -- Creates directories recursive and sets mode to optional mode paramter.</pre>
1549
1550
1551 <pre class="prettyprint lang-lua">r:rmdir(dir) -- Removes a directory.</pre>
1552
1553
1554 <pre class="prettyprint lang-lua">r:touch(file [,mtime]) -- Sets the file modification time to current time or to optional mtime msec value.</pre>
1555
1556
1557 <pre class="prettyprint lang-lua">r:get_direntries(dir) -- Returns a table with all directory entries.
1558
1559 function handle(r)
1560   local dir = r.context_document_root
1561   for _, f in ipairs(r:get_direntries(dir)) do
1562     local info = r:stat(dir .. "/" .. f)
1563     if info then
1564       local mtime = os.date(fmt, info.mtime / 1000000)
1565       local ftype = (info.filetype == 2) and "[dir] " or "[file]"
1566       r:puts( ("%s %s %10i %s\n"):format(ftype, mtime, info.size, f) )
1567     end
1568   end
1569 end</pre>
1570
1571
1572 <pre class="prettyprint lang-lua">r.date_parse_rfc(string) -- Parses a date/time string and returns seconds since epoche.</pre>
1573
1574
1575 <pre class="prettyprint lang-lua">r:getcookie(key) -- Gets a HTTP cookie</pre>
1576
1577
1578 <pre class="prettyprint lang-lua">r:setcookie{
1579   key = [key],
1580   value = [value],
1581   expires = [expiry],
1582   secure = [boolean],
1583   httponly = [boolean],
1584   path = [path],
1585   domain = [domain]
1586 } -- Sets a HTTP cookie, for instance:
1587
1588 r:setcookie{
1589   key = "cookie1",
1590   value = "HDHfa9eyffh396rt",
1591   expires = os.time() + 86400,
1592   secure = true
1593 }</pre>
1594
1595
1596 <pre class="prettyprint lang-lua">r:wsupgrade() -- Upgrades a connection to WebSockets if possible (and requested):
1597 if r:wsupgrade() then -- if we can upgrade:
1598     r:wswrite("Welcome to websockets!") -- write something to the client
1599     r:wsclose()  -- goodbye!
1600 end</pre>
1601
1602
1603 <pre class="prettyprint lang-lua">r:wsread() -- Reads a WebSocket frame from a WebSocket upgraded connection (see above):
1604
1605 local line, isFinal = r:wsread() -- isFinal denotes whether this is the final frame.
1606                                  -- If it isn't, then more frames can be read
1607 r:wswrite("You wrote: " .. line)</pre>
1608
1609
1610 <pre class="prettyprint lang-lua">r:wswrite(line) -- Writes a frame to a WebSocket client:
1611 r:wswrite("Hello, world!")</pre>
1612
1613
1614 <pre class="prettyprint lang-lua">r:wsclose() -- Closes a WebSocket request and terminates it for httpd:
1615
1616 if r:wsupgrade() then
1617     r:wswrite("Write something: ")
1618     local line = r:wsread() or "nothing"
1619     r:wswrite("You wrote: " .. line);
1620     r:wswrite("Goodbye!")
1621     r:wsclose()
1622 end</pre>
1623
1624
1625 <pre class="prettyprint lang-lua">r:wspeek() -- Checks if any data is ready to be read
1626
1627 -- Sleep while nothing is being sent to us...
1628 while r:wspeek() == false do
1629    r.usleep(50000)
1630 end
1631 -- We have data ready!
1632 local line = r:wsread()</pre>
1633
1634
1635
1636 <pre class="prettyprint lang-lua">r:config() -- Get a walkable tree of the entire httpd configuration</pre>
1637
1638
1639 <pre class="prettyprint lang-lua">r:activeconfig() -- Get a walkable tree of the active (virtualhost-specific) httpd configuration</pre>
1640
1641
1642
1643 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1644 <div class="section">
1645 <h2><a name="logging" id="logging">Logging Functions</a></h2>
1646
1647 <pre class="prettyprint lang-lua">        -- examples of logging messages<br />
1648         r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
1649         r:debug("This is a debug log message")<br />
1650         r:info("This is an info log message")<br />
1651         r:notice("This is a notice log message")<br />
1652         r:warn("This is a warn log message")<br />
1653         r:err("This is an err log message")<br />
1654         r:alert("This is an alert log message")<br />
1655         r:crit("This is a crit log message")<br />
1656         r:emerg("This is an emerg log message")<br />
1657 </pre>
1658
1659
1660 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1661 <div class="section">
1662 <h2><a name="apache2" id="apache2">apache2 Package</a></h2>
1663 <p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
1664 <dl>
1665   <dt>apache2.OK</dt>
1666   <dd>internal constant OK.  Handlers should return this if they've
1667   handled the request.</dd>
1668   <dt>apache2.DECLINED</dt>
1669   <dd>internal constant DECLINED.  Handlers should return this if
1670   they are not going to handle the request.</dd>
1671   <dt>apache2.DONE</dt>
1672   <dd>internal constant DONE.</dd>
1673   <dt>apache2.version</dt>
1674   <dd>Apache HTTP server version string</dd>
1675   <dt>apache2.HTTP_MOVED_TEMPORARILY</dt>
1676   <dd>HTTP status code</dd>
1677   <dt>apache2.PROXYREQ_NONE, apache2.PROXYREQ_PROXY, apache2.PROXYREQ_REVERSE, apache2.PROXYREQ_RESPONSE</dt>
1678   <dd>internal constants used by <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code></dd>
1679   <dt>apache2.AUTHZ_DENIED, apache2.AUTHZ_GRANTED, apache2.AUTHZ_NEUTRAL, apache2.AUTHZ_GENERAL_ERROR, apache2.AUTHZ_DENIED_NO_USER</dt>
1680   <dd>internal constants used by <code class="module"><a href="../mod/mod_authz_core.html">mod_authz_core</a></code></dd>
1681
1682 </dl>
1683 <p>(Other HTTP status codes are not yet implemented.)</p>
1684 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1685 <div class="section">
1686 <h2><a name="modifying_buckets" id="modifying_buckets">Modifying contents with Lua filters</a></h2>
1687     
1688     <p>
1689     Filter functions implemented via <code class="directive"><a href="#luainputfilter">LuaInputFilter</a></code> 
1690     or <code class="directive"><a href="#luaoutputfilter">LuaOutputFilter</a></code> are designed as 
1691     three-stage non-blocking functions using coroutines to suspend and resume a 
1692     function as buckets are sent down the filter chain. The core structure of 
1693     such a function is:
1694     </p>
1695     <pre class="prettyprint lang-lua">function filter(r)
1696     -- Our first yield is to signal that we are ready to receive buckets.
1697     -- Before this yield, we can set up our environment, check for conditions,
1698     -- and, if we deem it necessary, decline filtering a request alltogether:
1699     if something_bad then
1700         return -- This would skip this filter.
1701     end
1702     -- Regardless of whether we have data to prepend, a yield MUST be called here.
1703     -- Note that only output filters can prepend data. Input filters must use the 
1704     -- final stage to append data to the content.
1705     coroutine.yield([optional header to be prepended to the content])
1706     
1707     -- After we have yielded, buckets will be sent to us, one by one, and we can 
1708     -- do whatever we want with them and then pass on the result.
1709     -- Buckets are stored in the global variable 'bucket', so we create a loop
1710     -- that checks if 'bucket' is not nil:
1711     while bucket ~= nil do
1712         local output = mangle(bucket) -- Do some stuff to the content
1713         coroutine.yield(output) -- Return our new content to the filter chain
1714     end
1715
1716     -- Once the buckets are gone, 'bucket' is set to nil, which will exit the 
1717     -- loop and land us here. Anything extra we want to append to the content
1718     -- can be done by doing a final yield here. Both input and output filters 
1719     -- can append data to the content in this phase.
1720     coroutine.yield([optional footer to be appended to the content])
1721 end</pre>
1722
1723 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
1724 <div class="section">
1725 <h2><a name="databases" id="databases">Database connectivity</a></h2>
1726     
1727     <p>
1728     Mod_lua implements a simple database feature for querying and running commands
1729     on the most popular database engines (mySQL, PostgreSQL, FreeTDS, ODBC, SQLite, Oracle)
1730     as well as mod_dbd.
1731     </p>
1732     <p>The example below shows how to acquire a database handle and return information from a table:</p>
1733     <pre class="prettyprint lang-lua">function handle(r)
1734     -- Acquire a database handle
1735     local database, err = r:dbacquire("mysql", "server=localhost,user=someuser,pass=somepass,dbname=mydb")
1736     if not err then
1737         -- Select some information from it
1738         local results, err = database:select(r, "SELECT `name`, `age` FROM `people` WHERE 1")
1739         if not err then
1740             local rows = results(0) -- fetch all rows synchronously
1741             for k, row in pairs(rows) do
1742                 r:puts( string.format("Name: %s, Age: %s&lt;br/&gt;", row[1], row[2]) )
1743             end
1744         else
1745             r:puts("Database query error: " .. err)
1746         end
1747         database:close()
1748     else
1749         r:puts("Could not connect to the database: " .. err)
1750     end
1751 end</pre>
1752
1753     <p>
1754     To utilize <code class="module"><a href="../mod/mod_dbd.html">mod_dbd</a></code>, specify <code>mod_dbd</code>
1755     as the database type, or leave the field blank:
1756     </p>
1757     <pre class="prettyprint lang-lua">local database = r:dbacquire("mod_dbd")</pre>
1758
1759     <h3><a name="database_object" id="database_object">Database object and contained functions</a></h3>
1760         
1761         <p>The database object returned by <code>dbacquire</code> has the following methods:</p>
1762         <p><strong>Normal select and query from a database:</strong></p>
1763     <pre class="prettyprint lang-lua">-- Run a statement and return the number of rows affected:
1764 local affected, errmsg = database:query(r, "DELETE FROM `tbl` WHERE 1")
1765
1766 -- Run a statement and return a result set that can be used synchronously or async:
1767 local result, errmsg = database:select(r, "SELECT * FROM `people` WHERE 1")</pre>
1768
1769         <p><strong>Using prepared statements (recommended):</strong></p>
1770     <pre class="prettyprint lang-lua">-- Create and run a prepared statement:
1771 local statement, errmsg = database:prepare(r, "DELETE FROM `tbl` WHERE `age` &gt; %u")
1772 if not errmsg then
1773     local result, errmsg = statement:query(20) -- run the statement with age &gt; 20
1774 end
1775
1776 -- Fetch a prepared statement from a DBDPrepareSQL directive:
1777 local statement, errmsg = database:prepared(r, "someTag")
1778 if not errmsg then
1779     local result, errmsg = statement:select("John Doe", 123) -- inject the values "John Doe" and 123 into the statement
1780 end</pre>
1781
1782         <p><strong>Escaping values, closing databases etc:</strong></p>
1783     <pre class="prettyprint lang-lua">-- Escape a value for use in a statement:
1784 local escaped = database:escape(r, [["'|blabla]])
1785
1786 -- Close a database connection and free up handles:
1787 database:close()
1788
1789 -- Check whether a database connection is up and running:
1790 local connected = database:active()</pre>
1791
1792     
1793     <h3><a name="result_sets" id="result_sets">Working with result sets</a></h3>
1794     
1795     <p>The result set returned by <code>db:select</code> or by the prepared statement functions 
1796     created through <code>db:prepare</code> can be used to
1797     fetch rows synchronously or asynchronously, depending on the row number specified:<br />
1798     <code>result(0)</code> fetches all rows in a synchronous manner, returning a table of rows.<br />
1799     <code>result(-1)</code> fetches the next available row in the set, asynchronously.<br />
1800     <code>result(N)</code> fetches row number <code>N</code>, asynchronously:
1801     </p>
1802     <pre class="prettyprint lang-lua">-- fetch a result set using a regular query:
1803 local result, err = db:select(r, "SELECT * FROM `tbl` WHERE 1")
1804
1805 local rows = result(0) -- Fetch ALL rows synchronously
1806 local row = result(-1) -- Fetch the next available row, asynchronously
1807 local row = result(1234) -- Fetch row number 1234, asynchronously
1808 local row = result(-1, true) -- Fetch the next available row, using row names as key indexes.</pre>
1809
1810     <p>One can construct a function that returns an iterative function to iterate over all rows 
1811     in a synchronous or asynchronous way, depending on the async argument:
1812     </p>
1813     <pre class="prettyprint lang-lua">function rows(resultset, async)
1814     local a = 0
1815     local function getnext()
1816         a = a + 1
1817         local row = resultset(-1)
1818         return row and a or nil, row
1819     end
1820     if not async then
1821         return pairs(resultset(0))
1822     else
1823         return getnext, self
1824     end
1825 end
1826
1827 local statement, err = db:prepare(r, "SELECT * FROM `tbl` WHERE `age` &gt; %u")
1828 if not err then
1829      -- fetch rows asynchronously:
1830     local result, err = statement:select(20)
1831     if not err then
1832         for index, row in rows(result, true) do
1833             ....
1834         end
1835     end
1836
1837      -- fetch rows synchronously:
1838     local result, err = statement:select(20)
1839     if not err then
1840         for index, row in rows(result, false) do
1841             ....
1842         end
1843     end
1844 end</pre>
1845
1846     
1847     <h3><a name="closing_databases" id="closing_databases">Closing a database connection</a></h3>
1848         
1849
1850     <p>Database handles should be closed using <code>database:close()</code> when they are no longer
1851     needed. If you do not close them manually, they will eventually be garbage collected and 
1852     closed by mod_lua, but you may end up having too many unused connections to the database 
1853     if you leave the closing up to mod_lua. Essentially, the following two measures are
1854     the same:
1855     </p>
1856     <pre class="prettyprint lang-lua">-- Method 1: Manually close a handle
1857 local database = r:dbacquire("mod_dbd")
1858 database:close() -- All done
1859
1860 -- Method 2: Letting the garbage collector close it
1861 local database = r:dbacquire("mod_dbd")
1862 database = nil -- throw away the reference
1863 collectgarbage() -- close the handle via GC</pre>
1864
1865     
1866     <h3><a name="database_caveat" id="database_caveat">Precautions when working with databases</a></h3>
1867     
1868     <p>Although the standard <code>query</code> and <code>run</code> functions are freely 
1869     available, it is recommended that you use prepared statements whenever possible, to 
1870     both optimize performance (if your db handle lives on for a long time) and to minimize 
1871     the risk of SQL injection attacks. <code>run</code> and <code>query</code> should only
1872     be used when there are no variables inserted into a statement (a static statement). 
1873     When using dynamic statements, use <code>db:prepare</code> or <code>db:prepared</code>.
1874     </p>
1875     
1876
1877 </div>
1878 </div>
1879 <div class="bottomlang">
1880 <p><span>Available Languages: </span><a href="../en/mod/mod_lua.html" title="English">&nbsp;en&nbsp;</a> |
1881 <a href="../fr/mod/mod_lua.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a></p>
1882 </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>
1883 <script type="text/javascript"><!--//--><![CDATA[//><!--
1884 var comments_shortname = 'httpd';
1885 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_lua.html';
1886 (function(w, d) {
1887     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
1888         d.write('<div id="comments_thread"><\/div>');
1889         var s = d.createElement('script');
1890         s.type = 'text/javascript';
1891         s.async = true;
1892         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
1893         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
1894     }
1895     else {
1896         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
1897     }
1898 })(window, document);
1899 //--><!]]></script></div><div id="footer">
1900 <p class="apache">Copyright 2015 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>
1901 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.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[//><!--
1902 if (typeof(prettyPrint) !== 'undefined') {
1903     prettyPrint();
1904 }
1905 //--><!]]></script>
1906 </body></html>