mod_lua.xml revision 880f77d700bc15c83bb541a053cd56e89cbfb8bc
fb51a6b789d85113d0976148685b0063c294220drbowen<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
77a0265761f1bec2aaa0b4116c644f8066e349e3rbowen<!-- $LastChangedRevision$ -->
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen Licensed to the Apache Software Foundation (ASF) under one or more
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen contributor license agreements. See the NOTICE file distributed with
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen this work for additional information regarding copyright ownership.
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen The ASF licenses this file to You under the Apache License, Version 2.0
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen (the "License"); you may not use this file except in compliance with
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen the License. You may obtain a copy of the License at
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen Unless required by applicable law or agreed to in writing, software
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen distributed under the License is distributed on an "AS IS" BASIS,
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen See the License for the specific language governing permissions and
b07b82e44c32825d6226ee801d2ed91555e593d1rbowen limitations under the License.
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<description>Provides Lua hooks into various portions of the httpd
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowenrequest processing</description>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim<p>This module allows the server to be extended with scripts written in the
889dc1728817c1c56d0c8d894c768614e346d86ecovenerLua programming language. The extension points (hooks) available with
889dc1728817c1c56d0c8d894c768614e346d86ecovener<module>mod_lua</module> include many of the hooks available to
889dc1728817c1c56d0c8d894c768614e346d86ecovenernatively compiled Apache HTTP Server modules, such as mapping requests to
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jimfiles, generating dynamic responses, access control, authentication, and
889dc1728817c1c56d0c8d894c768614e346d86ecovenerauthorization</p>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim<p>More information on the Lua programming language can be found at the
889dc1728817c1c56d0c8d894c768614e346d86ecovener<a href="http://www.lua.org/">the Lua website</a>.</p>
8548ace6aa09b4d3e463254b53865fb38fbbbc78poirier<note><code>mod_lua</code> is still in experimental state.
8548ace6aa09b4d3e463254b53865fb38fbbbc78poirierUntil it is declared stable, usage and behavior may change
8ad875ad9725307fd052e36abc2938f89f56902csfat any time, even between stable releases of the 2.4.x series.
8ad875ad9725307fd052e36abc2938f89f56902csfBe sure to check the CHANGES file before upgrading.</note>
ededb790277bba8f7ae292b5385aecc7ac433105humbedooh<section id="basicconf"><title>Basic Configuration</title>
3e30fa5f420fe7302a4cdcd79cb001958fd54a13rbowen<code>mod_lua</code> provides a handler named <code>lua-script</code>,
fb51a6b789d85113d0976148685b0063c294220drbowenwhich can be used with an <code>AddHandler</code> directive:</p>
6265962c731aed3af3aa7242b35852f3f181d437humbedoohAddHandler lua-script .lua
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowenThis will cause <code>mod_lua</code> to handle requests for files
fb51a6b789d85113d0976148685b0063c294220drbowen<p>For more flexibility, see <directive>LuaMapHandler</directive>.
4b2d52ed83bf31730c8b6bbe7c06d806dc3a0c4erbowen<section id="writinghandlers"><title>Writing Handlers</title>
92e5d4326ae44f79da5cb049470daba604506846poirier<p> In the Apache HTTP Server API, the handler is a specific kind of hook
92e5d4326ae44f79da5cb049470daba604506846poirierresponsible for generating the response. Examples of modules that include a
92e5d4326ae44f79da5cb049470daba604506846poirierhandler are <module>mod_proxy</module>, <module>mod_cgi</module>,
fb51a6b789d85113d0976148685b0063c294220drbowen<p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenjust evaluating a script body CGI style. A handler function looks
889dc1728817c1c56d0c8d894c768614e346d86ecovenersomething like this:</p>
889dc1728817c1c56d0c8d894c768614e346d86ecovener-- example handler
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenrequire "string"
880f77d700bc15c83bb541a053cd56e89cbfb8bchumbedooh This is the default method name for Lua handlers, see the optional
991f8cc9d508110a59a25a84f8c8d8d129c49859humbedooh function-name in the LuaMapHandler directive to choose a different
92e5d4326ae44f79da5cb049470daba604506846poirier entry point.
92e5d4326ae44f79da5cb049470daba604506846poirierfunction handle(r)
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim r:puts("Hello Lua World!\n")
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim if r.method == 'GET' then
cf7d90693f7579700c4f7e663adb83196f903df1covener for k, v in pairs( r:parseargs() ) do
cf7d90693f7579700c4f7e663adb83196f903df1covener r:puts( string.format("%s: %s", k, v) )
92e5d4326ae44f79da5cb049470daba604506846poirier elseif r.method == 'POST' then
92e5d4326ae44f79da5cb049470daba604506846poirier for k, v in pairs( r:parsebody() ) do
92e5d4326ae44f79da5cb049470daba604506846poirier r:puts( string.format("%s: %s", k, v) )
a51fa5c4960c597687688fd4a87856d5db51435fhumbedooh r:puts("unknown HTTP method " .. r.method)
ced1589c6d84766b80b17671236248cd6b6f2645covener</highlight>
92e5d4326ae44f79da5cb049470daba604506846poirierThis handler function just prints out the uri or form encoded
ced1589c6d84766b80b17671236248cd6b6f2645covenerarguments to a plaintext page.
ced1589c6d84766b80b17671236248cd6b6f2645covenerThis means (and in fact encourages) that you can have multiple
ced1589c6d84766b80b17671236248cd6b6f2645covenerhandlers (or hooks, or filters) in the same script.
92e5d4326ae44f79da5cb049470daba604506846poirier<section id="writinghooks"><title>Writing Hooks</title>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<p>Hook functions are how modules (and Lua scripts) participate in the
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenprocessing of requests. Each type of hook exposed by the server exists for
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowena specific purposes such as mapping requests to the filesystem,
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenperforming access control, or setting mimetypes. General purpose hooks
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenthat simply run at handy times in the request lifecycle exist as well.</p>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<p>Hook functions are passed the request object as their only argument.
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenThey can return any value, depending on the hook, but most commonly
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowenthey'll return OK, DONE, or DECLINED, which you can write in lua as
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<code>apache2.OK</code>, <code>apache2.DONE</code>, or
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen<code>apache2.DECLINED</code>, or else an HTTP status code.</p>
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf-- example hook that rewrites the URI to a filesystem path.
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sfrequire 'apache2'
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sffunction translate_name(r)
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf if r.uri == "/translate-name" then
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf -- we don't care about this URL, give another module a chance
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf</highlight>
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf--[[ example hook that rewrites one URI to another URI. It returns a
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf apache2.DECLINED to give other URL mappers a chance to work on the
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf substitution, including the core translate_name hook which maps based
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf on the DocumentRoot.
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf Note: It is currently undefined as to whether this runs before or after
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf mod_alias.
991f8cc9d508110a59a25a84f8c8d8d129c49859humbedoohrequire 'apache2'
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sffunction translate_name(r)
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf if r.uri == "/translate-name" then
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf</highlight>
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf<section id="datastructures"><title>Data Structures</title>
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf <p>The request_rec is mapped in as a userdata. It has a metatable
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf which lets you do useful things with it. For the most part it
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf has the same fields as the request_rec struct (see httpd.h
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf until we get better docs here) many of which are writeable as
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf well as readable. (The table fields' content can be changed, but the
e20c6ecbd465cd7dabb44acea6afafc7925f3a03sf fields themselves cannot be set to different tables.)</p>
e27eee5caa6c1bf3853c11253ae82303cff0e40brbowen <p>The request_rec has (at least) the following methods:</p>
df26612d249def4d0b228be69bf89d038d6a129ehumbedooh r:addoutputfilter(name|function) -- add an output filter
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh r:parseargs() -- returns a lua table containing the request's
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier query string arguments
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:parsebody() -- parse the request body as a POST and return
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh r:puts("hello", " world", "!") -- print to response body
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:write("a single string") -- print to response body
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<section id="logging"><title>Logging Functions</title>
fc57cc74ee4e73618f74a7a62ea6ac77546666dacovener -- examples of logging messages<br />
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh r:debug("This is a debug log message")<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:info("This is an info log message")<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:notice("This is an notice log message")<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:warn("This is an warn log message")<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:err("This is an err log message")<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier r:alert("This is an alert log message")<br />
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh r:crit("This is an crit log message")<br />
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh r:emerg("This is an emerg log message")<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</highlight>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<section id="apache2"><title>apache2 Package</title>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh <dd>internal constant OK. Handlers should return this if they've
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh handled the request.</dd>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh <dd>internal constant DECLINED. Handlers should return this if
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh they are not going to handle the request.</dd>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <dt>apache2.PROXYREQ_NONE, apache2.PROXYREQ_PROXY, apache2.PROXYREQ_REVERSE, apache2.PROXYREQ_RESPONSE</dt>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <dd>internal constants used by <module>mod_proxy</module></dd>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<p>(Other HTTP status codes are not yet implemented.)</p>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<directivesynopsis>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<description>Specify the base path for resolving relative paths for mod_lua directives</description>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<context>directory</context><context>.htaccess</context>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</contextlist>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh <p>Specify the base path which will be used to evaluate all
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh relative paths within mod_lua. If not specified they
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier will be resolved relative to the current working directory,
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf which may not always work well for a server.</p>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf</directivesynopsis>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<directivesynopsis>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf<description>One of once, request, conn, server -- default is once</description>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf<syntax>LuaScope once|request|conn|server [max|min max]</syntax>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf<contextlist><context>server config</context><context>virtual host</context>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<context>directory</context><context>.htaccess</context>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf</contextlist>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <p>Specify the lifecycle scope of the Lua interpreter which will
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier be used by handlers in this "Directory." The default is "once"</p>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <dt>request:</dt> <dd>use the interpreter to handle anything based on
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier the same file within this request, which is also
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh request scoped.</dd>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <dt>server:</dt> <dd>This one is different than others because the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier server scope is quite long lived, and multiple threads
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier will have the same server_rec. To accommodate this
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh server scoped interpreter are stored in an apr
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh resource list. The min and max arguments are intended
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh to specify the pool size, but are unused at this time.</dd>
7152f5d04e3782c5e93016ae2ccd960f8538b83bcovener</directivesynopsis>
7152f5d04e3782c5e93016ae2ccd960f8538b83bcovener<directivesynopsis>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<description>Map a path to a lua handler</description>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<syntax>LuaMapHandler uri-pattern /path/to/lua/script.lua [function-name]</syntax>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<context>directory</context><context>.htaccess</context>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh</contextlist>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <p>This directive matches a uri pattern to invoke a specific
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier handler function in a specific file. It uses PCRE regular
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier expressions to match the uri, and supports interpolating
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier match groups into both the file path and the function name
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh be careful writing your regular expressions to avoid security
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier LuaMapHandler /(\w+)/(/w+) /scripts/$1.lua handle_$2
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh handler function handle_show on the lua vm after
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier loading that file.</p>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh <p>This would invoke the "handle" function, which
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh is the default if no specific function name is
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh provided.</p>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh</directivesynopsis>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<directivesynopsis>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<description>Add a directory to lua's package.path</description>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<syntax>LuaPackagePath /path/to/include/?.lua</syntax>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<contextlist><context>server config</context><context>virtual host</context>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<context>directory</context><context>.htaccess</context>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh</contextlist>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh <usage><p>Add a path to lua's module search path. Follows the same
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh conventions as lua. This just munges the package.path in the
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh lua vms.</p>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf </example>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf</directivesynopsis>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf<directivesynopsis>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<description>Add a directory to lua's package.cpath</description>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<syntax>LuaPackageCPath /path/to/include/?.soa</syntax>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<contextlist><context>server config</context><context>virtual host</context>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<context>directory</context><context>.htaccess</context>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</contextlist>
92e5d4326ae44f79da5cb049470daba604506846poirier <p>Add a path to lua's shared library search path. Follows the same
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh conventions as lua. This just munges the package.cpath in the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier lua vms.</p>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh</directivesynopsis>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<directivesynopsis>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<description>Configure the compiled code cache.</description>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<contextlist><context>server config</context><context>virtual host</context>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<context>directory</context><context>.htaccess</context>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</contextlist>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh Specify the behavior of the in-memory code cache. The default
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh is stat, which stats the top level script (not any included
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh ones) each time that file is needed, and reloads it if the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier modified time indicates it is newer than the one it has
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier already loaded. The other values cause it to keep the file
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier cached forever (don't stat and replace) or to never cache the
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <p>In general stat or forever is good for production, and stat or never
7152f5d04e3782c5e93016ae2ccd960f8538b83bcovener for development.</p>
7152f5d04e3782c5e93016ae2ccd960f8538b83bcovener LuaCodeCache stat<br />
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh LuaCodeCache forever<br />
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh LuaCodeCache never<br />
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</directivesynopsis>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<directivesynopsis>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<description>Provide a hook for the translate name phase of request processing</description>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<syntax>LuaHookTranslateName /path/to/lua/script.lua hook_function_name [early|late]</syntax>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<contextlist><context>server config</context><context>virtual host</context>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh</contextlist>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh request processing. The hook function receives a single
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh argument, the request_rec, and should return a status code,
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh which is either an HTTP error code, or the constants defined
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh in the apache2 module: apache2.OK, apache2.DECLINED, or
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh <p>For those new to hooks, basically each hook will be invoked
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh until one of them returns apache2.OK. If your hook doesn't
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh want to do the translation it should just return
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh apache2.DECLINED. If the request should stop processing, then
8230057b2a5c382433ec1d7a9d1e3f1bb1daa87acovenerLuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
10961a2f60207cb873d889bb28b1f0ef707a4311humbedoohrequire "apache2"
10961a2f60207cb873d889bb28b1f0ef707a4311humbedoohfunction silly_mapper(r)
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh if r.uri == "/" then
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <note><title>Context</title><p>This directive is not valid in <directive
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier type="section" module="core">Directory</directive>, <directive
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier type="section" module="core">Files</directive>, or htaccess
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier <note><title>Ordering</title><p>The optional arguments "early" or "late"
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier control when this script runs relative to other modules.</p></note>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</directivesynopsis>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<directivesynopsis>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<description>Provide a hook for the fixups phase of request
249cc9b3d83d3c60666269b90ecb9f1390d32165poirierprocessing</description>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<syntax>LuaHookFixups /path/to/lua/script.lua hook_function_name</syntax>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<context>directory</context><context>.htaccess</context>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</contextlist>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh Just like LuaHookTranslateName, but executed at the fixups phase
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf</directivesynopsis>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf<directivesynopsis>
f5b3f41700a107b9df2b3c5a1cc3e5ea775fd8fesf<description>Provide a hook for the map_to_storage phase of request processing</description>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier<syntax>LuaHookMapToStorage /path/to/lua/script.lua hook_function_name</syntax>
887ddb3e9bc5857cf9ce17263be412c6d8339c03humbedooh<contextlist><context>server config</context><context>virtual host</context>
887ddb3e9bc5857cf9ce17263be412c6d8339c03humbedooh<context>directory</context><context>.htaccess</context>
887ddb3e9bc5857cf9ce17263be412c6d8339c03humbedooh</contextlist>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<directivesynopsis>
df26612d249def4d0b228be69bf89d038d6a129ehumbedooh<description>Provide a hook for the check_user_id phase of request processing</description>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh<syntax>LuaHookCheckUserID /path/to/lua/script.lua hook_function_name [early|late]</syntax>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<context>directory</context><context>.htaccess</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</contextlist>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim <note><title>Ordering</title><p>The optional arguments "early" or "late"
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh control when this script runs relative to other modules.</p></note>
10961a2f60207cb873d889bb28b1f0ef707a4311humbedooh</directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<description>Provide a hook for the type_checker phase of request processing</description>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<syntax>LuaHookTypeChecker /path/to/lua/script.lua hook_function_name</syntax>
65305d236fe992253daa6ee6b3176a8e0e2d87e1humbedooh<contextlist><context>server config</context><context>virtual host</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<context>directory</context><context>.htaccess</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</contextlist>
249cc9b3d83d3c60666269b90ecb9f1390d32165poirier</directivesynopsis>
ef9c39be3d095e25d3a9fe681d7b9c5400506e5fhumbedooh<directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<description>Provide a hook for the auth_checker phase of request processing</description>
ef9c39be3d095e25d3a9fe681d7b9c5400506e5fhumbedooh<syntax>LuaHookAuthChecker /path/to/lua/script.lua hook_function_name [early|late]</syntax>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<context>directory</context><context>.htaccess</context>
1abe2f0d024bcb5d099cef68af06781da4e3270bhumbedooh</contextlist>
ef9c39be3d095e25d3a9fe681d7b9c5400506e5fhumbedooh<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
ef9c39be3d095e25d3a9fe681d7b9c5400506e5fhumbedooh<p>Invoke a lua function in the auth_checker phase of processing
ef9c39be3d095e25d3a9fe681d7b9c5400506e5fhumbedooha request. This can be used to implement arbitrary authentication
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedoohand authorization checking. A very simple example:
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedoohrequire 'apache2'
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh-- fake authcheck hook
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh-- If request has no auth info, set the response header and
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh-- return a 401 to ask the browser for basic auth info.
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh-- If request has auth info, don't actually look at it, just
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh-- pretend we got userid 'foo' and validated it.
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh-- Then check if the userid is 'foo' and accept the request.
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedoohfunction authcheck_hook(r)
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh -- look for auth info
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh auth = r.headers_in['Authorization']
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh if auth ~= nil then
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh -- fake the user
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh if r.user == nil then
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh r:debug("authcheck: user is nil, returning 401")
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh elseif r.user == "foo" then
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh r:debug('user foo: OK')
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh r:debug("authcheck: user='" .. r.user .. "'")
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh <note><title>Ordering</title><p>The optional arguments "early" or "late"
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh control when this script runs relative to other modules.</p></note>
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh</directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<description>Provide a hook for the access_checker phase of request processing</description>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<syntax>LuaHookAccessChecker /path/to/lua/script.lua hook_function_name [early|late]</syntax>
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh<contextlist><context>server config</context><context>virtual host</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<context>directory</context><context>.htaccess</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</contextlist>
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<p>Add your hook to the access_checker phase. An access checker
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedoohhook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh <note><title>Ordering</title><p>The optional arguments "early" or "late"
419966e1a7019b758486432515281fa570920866fuankg control when this script runs relative to other modules.</p></note>
419966e1a7019b758486432515281fa570920866fuankg</directivesynopsis>
419966e1a7019b758486432515281fa570920866fuankg<directivesynopsis>
419966e1a7019b758486432515281fa570920866fuankg<description>Provide a hook for the insert_filter phase of request processing</description>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<syntax>LuaHookInsertFilter /path/to/lua/script.lua hook_function_name</syntax>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<context>directory</context><context>.htaccess</context>
f193d325b0241c29fdd45cce7e1458b11324677cfuankg</contextlist>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<description>Controls how parent configuration sections are merged into children</description>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<syntax>LuaInherit none|parent-first|parent-last</syntax>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<context>directory</context><context>.htaccess</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</contextlist>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh <usage><p>By default, if LuaHook* directives are used in overlapping
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh Directory or Location configuration sections, the scripts defined in the
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh more specific section are run <em>after</em> those defined in the more
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh generic section (LuaInherit parent-first). You can reverse this order, or
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh make the parent context not apply at all.</p>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh <p> In previous 2.3.x releases, the default was effectively to ignore LuaHook*
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh directives from parent configuration sections.</p></usage>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<description>Provide a hook for the quick handler of request processing</description>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh<contextlist><context>server config</context><context>virtual host</context>
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh<context>directory</context><context>.htaccess</context>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</contextlist>
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh <note><title>Context</title><p>This directive is not valid in <directive
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh type="section" module="core">Directory</directive>, <directive
e53ae81ffa6d05c08191384c5c6040dee6d1d7d2humbedooh type="section" module="core">Files</directive>, or htaccess
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</directivesynopsis>
7c3e1c5ca4a644b99873755515503db42b869a4bhumbedooh</modulesynopsis>