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