mod_lua.xml revision b60ba9fb00026d3dbca744c6c19afe63cba3a3d1
c30ef289fe64ac7fedc44cfcc6b439f0f8458b4cgregames<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
c30ef289fe64ac7fedc44cfcc6b439f0f8458b4cgregames<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
5541a81e194dc99521c0ecf904a940b0b65a93f2nd<!-- $LastChangedRevision$ -->
8eeb24cab1b849bd17726d0a030cd299209f108cnd Licensed to the Apache Software Foundation (ASF) under one or more
8eeb24cab1b849bd17726d0a030cd299209f108cnd contributor license agreements. See the NOTICE file distributed with
8eeb24cab1b849bd17726d0a030cd299209f108cnd this work for additional information regarding copyright ownership.
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpj The ASF licenses this file to You under the Apache License, Version 2.0
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpj (the "License"); you may not use this file except in compliance with
7edcfe02796a70f2a5eac12b6766d11067c629a3rederpj the License. You may obtain a copy of the License at
a4dd3688dd6645faf0c1c1bfb22017c8f03d5b24nd Unless required by applicable law or agreed to in writing, software
a4dd3688dd6645faf0c1c1bfb22017c8f03d5b24nd distributed under the License is distributed on an "AS IS" BASIS,
a4dd3688dd6645faf0c1c1bfb22017c8f03d5b24nd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a16ca336064074171bffc3a6da3444243a06b62btrawick See the License for the specific language governing permissions and
a16ca336064074171bffc3a6da3444243a06b62btrawick limitations under the License.
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd<description>Provides Lua hooks into various portions of the httpd
7de6cb79f71a9007ba2b1e786cbad8b84f05d101ndrequest processing</description>
862562bece2467ae2e729a270279e07522c654a9rederpj<p>This module allows the server to be extended with scripts written in the
862562bece2467ae2e729a270279e07522c654a9rederpjLua programming language. The extension points (hooks) available with
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawick<module>mod_lua</module> include many of the hooks available to
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawicknatively compiled Apache HTTP Server modules, such as mapping requests to
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawickfiles, generating dynamic responses, access control, authentication, and
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpjauthorization</p>
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpj<p>More information on the Lua programming language can be found at the
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpj<a href="http://www.lua.org/">the Lua website</a>.</p>
d1c46782edbd6bd5ae4592c0174969950c5ca8aetrawick<note><code>mod_lua</code> is still in experimental state.
d1c46782edbd6bd5ae4592c0174969950c5ca8aetrawickUntil it is declared stable, usage and behavior may change
a3954060338ccebc73071e89ac936d4ec15ab352trawickat any time.</note>
ab56518227d474ee08f039e4c5540011c1b8a913trawick<section id="basicconf"><title>Basic Configuration</title>
219e31b849ef108cd8f58ba0eedae03414e5edb1thommay<code>mod_lua</code> provides a handler named <code>lua-script</code>,
a98959721afc481c7f3a941f85c462f0b90defdathommaywhich can be used with an <code>AddHandler</code> directive:</p>
219e31b849ef108cd8f58ba0eedae03414e5edb1thommayAddHandler lua-script .lua
dbb916b882c33a4e340b0dba7d75506cfdd85640trawickThis will cause <code>mod_lua</code> to handle requests for files
9efe68be3c81ee85225972195fb725dbfc2e8b24trawick<p>For more flexibility, see <directive>LuaMapHandler</directive>.
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawick<section id="writinghandlers"><title>Writing Handlers</title>
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawick<p> In the Apache HTTP Server API, the handler is a specific kind of hook
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawickresponsible for generating the response. Examples of modules that include a
fc25339741311efd7d460f18b6287ef38d76bbe6madhumhandler are <module>mod_proxy</module>, <module>mod_cgi</module>,
fc25339741311efd7d460f18b6287ef38d76bbe6madhum<p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
fcdca175a52fe517f2317ba0e2b6e6d14522b869madhumjust evaluating a script body CGI style. A handler function looks
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantzsomething like this:</p>
92a2439559cf1161742650ed9c50c6483bd029cemadhum-- example handler
ebecc16986604cce1369d5075eff65032e3dd0deianhrequire "string"
764315969cef40e50cdc6a5e9638454e10c1c06end This is the default method name for Lua handlers, see the optional
764315969cef40e50cdc6a5e9638454e10c1c06end function-name in the LuaMapHandler directive to choose a different
764315969cef40e50cdc6a5e9638454e10c1c06end entry point.
bfb54bd96690887dcdf184fd9083c2e167898ce2ndfunction handle(r)
a2c036f0ca71e35c085b4cd9451a6d3718bc65daake r:puts("Hello Lua World!\n")
a2c036f0ca71e35c085b4cd9451a6d3718bc65daake if r.method == 'GET' then
b92cba59a0890be43b14aaf1ce30606140be9593nd for k, v in pairs( r:parseargs() ) do
b92cba59a0890be43b14aaf1ce30606140be9593nd r:puts( string.format("%s: %s", k, v) )
b92cba59a0890be43b14aaf1ce30606140be9593nd elseif r.method == 'POST' then
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick for k, v in pairs( r:parsebody() ) do
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick r:puts( string.format("%s: %s", k, v) )
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantz r:puts("unknown HTTP method " .. r.method)
9e398d701dd430f073ff5418fb720642e064046ajerenkrantzThis handler function just prints out the uri or form encoded
9e398d701dd430f073ff5418fb720642e064046ajerenkrantzarguments to a plaintext page.
a7ac9b52c3d9f7ce937f078a0d585023db626c55jerenkrantzThis means (and in fact encourages) that you can have multiple
a7ac9b52c3d9f7ce937f078a0d585023db626c55jerenkrantzhandlers (or hooks, or filters) in the same script.
db5837bbc9bef214303e755fa52122140366cb6fianh<p>Hook functions are how modules (and Lua scripts) participate in the
aac2b82fe4f1ac117e2a0702438d6615542642dandprocessing of requests. Each type of hook exposed by the server exists for
aac2b82fe4f1ac117e2a0702438d6615542642danda specific purposes such as mapping requests to the filesystem,
aac2b82fe4f1ac117e2a0702438d6615542642dandperforming access control, or setting mimetypes. General purpose hooks
a793d402c74e50326a2401cfbdc562c5781948fdndthat simply run at handy times in the request lifecycle exist as well.</p>
0a209fcb17b8c9a42a6149a1758e61cf6527d367nd<p>Hook functions are passed the request object as their only argument.
a793d402c74e50326a2401cfbdc562c5781948fdndThey can return any value, depending on the hook, but most commonly
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzthey'll return OK, DONE, or DECLINED, which you can write in lua as
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<code>apache2.OK</code>, <code>apache2.DONE</code>, or
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantz<code>apache2.DECLINED</code>, or else an HTTP status code.</p>
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz-- example hook that rewrites the URI to a filesystem path.
ab8c0315521735c73ce16c8072f91e17c406ca5bndrequire 'apache2'
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5ndfunction translate_name(r)
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5nd if r.uri == "/translate-name" then
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantz -- we don't care about this URL, give another module a chance
4cdc5446050c19b9d519a273a129188586e8d445jerenkrantz--[[ example hook that rewrites one URI to another URI. It returns a
4cdc5446050c19b9d519a273a129188586e8d445jerenkrantz apache2.DECLINED to give other URL mappers a chance to work on the
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard substitution, including the core translate_name hook which maps based
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard on the DocumentRoot.
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard Note: It is currently undefined as to whether this runs before or after
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantzrequire 'apache2'
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantzfunction translate_name(r)
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz if r.uri == "/translate-name" then
59b910556d04c82e951d6c6f7a413ab8fed21467trawick<section id="datastructures"><title>Data Structures</title>
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd <p>The request_rec is mapped in as a userdata. It has a metatable
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd which lets you do useful things with it. For the most part it
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick has the same fields as the request_rec struct (see httpd.h
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick until we get better docs here) many of which are writeable as
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick well as readable. (The table fields' content can be changed, but the
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick fields themselves cannot be set to different tables.)</p>
e08b3783b570fdea39520da5e6c174394e956d17nd <p>The request_rec has (at least) the following methods:</p>
e08b3783b570fdea39520da5e6c174394e956d17nd r:addoutputfilter(name|function) -- add an output filter
e08b3783b570fdea39520da5e6c174394e956d17nd </example>
16de8ff78c533f06c64d5ab2b685953992ff8659thommay r:parseargs() -- returns a lua table containing the request's
16de8ff78c533f06c64d5ab2b685953992ff8659thommay query string arguments
5aef954598e763eea457d204897a6a12d281755dtrawick r:parsebody() -- parse the request body as a POST and return
5aef954598e763eea457d204897a6a12d281755dtrawick a lua table
340e970018246649e86dd3ebbd34f4719e3ceaf7trawick r:puts("hello", " world", "!") -- print to response body
1360e9b0036040edfbcd2273ae18db83a93536detrawick r:write("a single string") -- print to response body
946f7bd76a0dec6d67af79af56a8cff3cb6ef9c1nd -- examples of logging messages<br />
946f7bd76a0dec6d67af79af56a8cff3cb6ef9c1nd r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
946f7bd76a0dec6d67af79af56a8cff3cb6ef9c1nd r:debug("This is a debug log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:info("This is an info log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:notice("This is an notice log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:warn("This is an warn log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:err("This is an err log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:alert("This is an alert log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:crit("This is an crit log message")<br />
8c038cdb417502a969599568ccc4020576d82a10nd r:emerg("This is an emerg log message")<br />
6838d0e05a193cb77265db36e3549201b3df57e6wrowe<p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe <dd>internal constant OK. Handlers should return this if they've
6838d0e05a193cb77265db36e3549201b3df57e6wrowe handled the request.</dd>
6fbf645df300ffa9c9693399571f2cd821af06fdtrawick <dd>internal constant DECLINED. Handlers should return this if
6fbf645df300ffa9c9693399571f2cd821af06fdtrawick they are not going to handle the request.</dd>
c8989f842c2ad4533950c13d99d3dfb099da0d67minfrin<p>(Other HTTP status codes are not yet implemented.)</p>
c8989f842c2ad4533950c13d99d3dfb099da0d67minfrin<directivesynopsis>
97610ac677a5eda4a3bb366c5bb34a27eeb4288cminfrin<description>Specify the base path for resolving relative paths for mod_lua directives</description>
6aa783d83f4304f664233d8252cb67116769676ewrowe<contextlist><context>server config</context><context>virtual host</context>
6aa783d83f4304f664233d8252cb67116769676ewrowe<context>directory</context><context>.htaccess</context>
6aa783d83f4304f664233d8252cb67116769676ewrowe</contextlist>
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd <p>Specify the base path which will be used to evaluate all
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd relative paths within mod_lua. If not specified they
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd will be resolved relative to the current working directory,
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd which may not always work well for a server.</p>
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd</directivesynopsis>
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd<directivesynopsis>
761fb8d21084bd7b7eb590fbd54a925dfdf806bbnd<description>One of once, request, conn, server -- default is once</description>
367cefc17f8dcfe65651c9c16cb3151589c6cecetrawick<syntax>LuaScope once|request|conn|server [max|min max]</syntax>
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe<contextlist><context>server config</context><context>virtual host</context>
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe<context>directory</context><context>.htaccess</context>
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe</contextlist>
6aa783d83f4304f664233d8252cb67116769676ewrowe <p>Specify the lifecycle scope of the Lua interpreter which will
6aa783d83f4304f664233d8252cb67116769676ewrowe be used by handlers in this "Directory." The default is "once"</p>
18f36c8bdc74f9fd18739b9a154852c541b18900minfrin <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
f1e73dbab9ba73d83c9ac8a13ab6150653bb71a9brianp <dt>request:</dt> <dd>use the interpreter to handle anything based on
f1e73dbab9ba73d83c9ac8a13ab6150653bb71a9brianp the same file within this request, which is also
7a01bcd2d59be7ec9ce55701c58054fa1c0bb5b6wrowe request scoped.</dd>
6aa783d83f4304f664233d8252cb67116769676ewrowe <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
7a01bcd2d59be7ec9ce55701c58054fa1c0bb5b6wrowe <dt>server:</dt> <dd>This one is different than others because the
7a01bcd2d59be7ec9ce55701c58054fa1c0bb5b6wrowe server scope is quite long lived, and multiple threads
9d71a9210ee030534400d37010f34e6a7d72b53fnd will have the same server_rec. To accommodate this
9d71a9210ee030534400d37010f34e6a7d72b53fnd server scoped interpreter are stored in an apr
9d71a9210ee030534400d37010f34e6a7d72b53fnd resource list. The min and max arguments are intended
9d71a9210ee030534400d37010f34e6a7d72b53fnd to specify the pool size, but are unused at this time.</dd>
5d6ffa7b5c77dd4132ed6d7f0dd63548b1c3c1c9nd</directivesynopsis>
5d6ffa7b5c77dd4132ed6d7f0dd63548b1c3c1c9nd<directivesynopsis>
144b1e2ebb48b2878017a8ac9a4cad1e771bc1b6stoddard<description>Map a path to a lua handler</description>
144b1e2ebb48b2878017a8ac9a4cad1e771bc1b6stoddard<syntax>LuaMapHandler uri-pattern /path/to/lua/script.lua [function-name]</syntax>
74b84dd6e146edc93cf1b3200e411bfc581f7c36nd<contextlist><context>server config</context><context>virtual host</context>
143a04461642dea548a4bebdb302f5e411528a14trawick<context>directory</context><context>.htaccess</context>
143a04461642dea548a4bebdb302f5e411528a14trawick</contextlist>
ebecc16986604cce1369d5075eff65032e3dd0deianh <p>This directive matches a uri pattern to invoke a specific
ebecc16986604cce1369d5075eff65032e3dd0deianh handler function in a specific file. It uses PCRE regular
ebecc16986604cce1369d5075eff65032e3dd0deianh expressions to match the uri, and supports interpolating
ebecc16986604cce1369d5075eff65032e3dd0deianh match groups into both the file path and the function name
ebecc16986604cce1369d5075eff65032e3dd0deianh be careful writing your regular expressions to avoid security
ebecc16986604cce1369d5075eff65032e3dd0deianh issues.</p>
7a2b9ea4788ea59d81b9e84192e4b90a9a0da875wrowe LuaMapHandler /(\w+)/(/w+) /scripts/$1.lua handle_$2
7a2b9ea4788ea59d81b9e84192e4b90a9a0da875wrowe handler function handle_show on the lua vm after
d225a894172ec361d2c6791638bacf604a8c6fa4nd loading that file.</p>
d225a894172ec361d2c6791638bacf604a8c6fa4nd <p>This would invoke the "handle" function, which
d225a894172ec361d2c6791638bacf604a8c6fa4nd is the default if no specific function name is
70f28b17978da5478a97843ab7cbcb4baf7a8711nd provided.</p>
70f28b17978da5478a97843ab7cbcb4baf7a8711nd</directivesynopsis>
ac539bd6714277d9ce7c39361de4cc11d1fb8eadnd<directivesynopsis>
ac539bd6714277d9ce7c39361de4cc11d1fb8eadnd<description>Add a directory to lua's package.path</description>
f5208b93c14accca0cd5f5acb042332b20172fb1nd<contextlist><context>server config</context><context>virtual host</context>
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe</contextlist>
1125f364c5cb4fd9bff71e89b5d4cbf551590035bnicholes <usage><p>Add a path to lua's module search path. Follows the same
1125f364c5cb4fd9bff71e89b5d4cbf551590035bnicholes conventions as lua. This just munges the package.path in the
1125f364c5cb4fd9bff71e89b5d4cbf551590035bnicholes lua vms.</p>
9d999c5deeddad9211695fc736a845afda6a2e95wrowe</directivesynopsis>
f19141958ebbfa8feb78e27007b4023d710d1c7etrawick<directivesynopsis>
f19141958ebbfa8feb78e27007b4023d710d1c7etrawick<description>Add a directory to lua's package.cpath</description>
3ac9911bdb9c066a068041218d5b05bc851340bdtrawick<syntax>LuaPackageCPath /path/to/include/?.soa</syntax>
3ac9911bdb9c066a068041218d5b05bc851340bdtrawick<contextlist><context>server config</context><context>virtual host</context>
3ac9911bdb9c066a068041218d5b05bc851340bdtrawick<context>directory</context><context>.htaccess</context>
c5c445b5614e4d5040d3c0994d2456f1ac8cb9b5jerenkrantz</contextlist>
c5c445b5614e4d5040d3c0994d2456f1ac8cb9b5jerenkrantz <p>Add a path to lua's shared library search path. Follows the same
c5c445b5614e4d5040d3c0994d2456f1ac8cb9b5jerenkrantz conventions as lua. This just munges the package.cpath in the
5541a81e194dc99521c0ecf904a940b0b65a93f2nd lua vms.</p>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe</directivesynopsis>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe<directivesynopsis>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe<description>Configure the compiled code cache.</description>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe<contextlist><context>server config</context><context>virtual host</context>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe<context>directory</context><context>.htaccess</context>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe</contextlist>
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe Specify the behavior of the in-memory code cache. The default
60736084c3e45fe7ece48483188e58b0f9e3a36bwrowe is stat, which stats the top level script (not any included
f16b2c3124a11bff93724342099e1afdb8145917bnicholes ones) each time that file is needed, and reloads it if the
d584e3b7a33da68233e7ac403213b436b402f5bend modified time indicates it is newer than the one it has
d584e3b7a33da68233e7ac403213b436b402f5bend already loaded. The other values cause it to keep the file
d584e3b7a33da68233e7ac403213b436b402f5bend cached forever (don't stat and replace) or to never cache the
d584e3b7a33da68233e7ac403213b436b402f5bend <p>In general stat or forever is good for production, and stat or never
d584e3b7a33da68233e7ac403213b436b402f5bend for development.</p>
d584e3b7a33da68233e7ac403213b436b402f5bend LuaCodeCache stat<br />
d584e3b7a33da68233e7ac403213b436b402f5bend LuaCodeCache forever<br />
d584e3b7a33da68233e7ac403213b436b402f5bend LuaCodeCache never<br />
d584e3b7a33da68233e7ac403213b436b402f5bend </example>
d584e3b7a33da68233e7ac403213b436b402f5bend</directivesynopsis>
d584e3b7a33da68233e7ac403213b436b402f5bend<directivesynopsis>
d584e3b7a33da68233e7ac403213b436b402f5bend<description>Provide a hook for the translate name phase of request processing</description>
3e49fe84a5024d831ffb14697747c5948821f958trawick<syntax>LuaHookTranslateName /path/to/lua/script.lua hook_function_name</syntax>
3e49fe84a5024d831ffb14697747c5948821f958trawick<contextlist><context>server config</context><context>virtual host</context>
3e49fe84a5024d831ffb14697747c5948821f958trawick<context>directory</context><context>.htaccess</context>
5610fc134df70e725bcdef518cc93de70261eb1dnd</contextlist>
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick request processing. The hook function receives a single
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick argument, the request_rec, and should return a status code,
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick which is either an HTTP error code, or the constants defined
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick in the apache2 module: apache2.OK, apache2.DECLINED, or
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick <p>For those new to hooks, basically each hook will be invoked
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick until one of them returns apache2.OK. If your hook doesn't
52d61f96a186861d991583851218e15ea16f0abetrawick want to do the translation it should just return
52d61f96a186861d991583851218e15ea16f0abetrawick apache2.DECLINED. If the request should stop processing, then
6838d0e05a193cb77265db36e3549201b3df57e6wroweLuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
74b84dd6e146edc93cf1b3200e411bfc581f7c36ndrequire "apache2"
11e365512cbf021726cd3ec3d80743f408170ff9stoddardfunction silly_mapper(r)
11e365512cbf021726cd3ec3d80743f408170ff9stoddard if r.uri == "/" then
1944ddbbad413b60307d66081b022a3eee5f04cfbnicholes</directivesynopsis>
1944ddbbad413b60307d66081b022a3eee5f04cfbnicholes<directivesynopsis>
3b1dc8f8f153d7167da9e64ab44f3e90f486a458wrowe<description>Provide a hook for the fixups phase of request
3b1dc8f8f153d7167da9e64ab44f3e90f486a458wroweprocessing</description>
3b1dc8f8f153d7167da9e64ab44f3e90f486a458wrowe<syntax>LuaHookFixups /path/to/lua/script.lua hook_function_name</syntax>
3b1dc8f8f153d7167da9e64ab44f3e90f486a458wrowe<contextlist><context>server config</context><context>virtual host</context>
2404b81d39a1a539f980d4808d52d23997a9e006nd</contextlist>
a3754e9d2edd5758f94fd743b9cf9f814be80383nd Just like LuaHookTranslateName, but executed at the fixups phase
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick</directivesynopsis>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick<directivesynopsis>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick<description>Provide a hook for the map_to_storage phase of request processing</description>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick<syntax>LuaHookMapToStorage /path/to/lua/script.lua hook_function_name</syntax>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick<contextlist><context>server config</context><context>virtual host</context>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick<context>directory</context><context>.htaccess</context>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe</contextlist>
5c870e08d589a24283cd76a9d596120605762cbbminfrin</directivesynopsis>
47d4dfaca60aff6d3c7e591bf593b3961cafcdefminfrin<directivesynopsis>
c206205e2475a7a4a192eaa7190a9894f01f0631minfrin<description>Provide a hook for the check_user_id phase of request processing</description>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe<syntax>LuaHookCheckUserID /path/to/lua/script.lua hook_function_name</syntax>
c206205e2475a7a4a192eaa7190a9894f01f0631minfrin<contextlist><context>server config</context><context>virtual host</context>
c206205e2475a7a4a192eaa7190a9894f01f0631minfrin<context>directory</context><context>.htaccess</context>
304aee4b1ff85cc876570493e4ed334d42b4d9eftrawick</contextlist>
304aee4b1ff85cc876570493e4ed334d42b4d9eftrawick</directivesynopsis>
304aee4b1ff85cc876570493e4ed334d42b4d9eftrawick<directivesynopsis>
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick<description>Provide a hook for the type_checker phase of request processing</description>
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick<syntax>LuaHookTypeChecker /path/to/lua/script.lua hook_function_name</syntax>
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick<contextlist><context>server config</context><context>virtual host</context>
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick<context>directory</context><context>.htaccess</context>
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe</contextlist>
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe</directivesynopsis>
111b2312c9749936ebca4f273db445820a0a703ebrianp<directivesynopsis>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick<description>Provide a hook for the auth_checker phase of request processing</description>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick<syntax>LuaHookAuthChecker /path/to/lua/script.lua hook_function_name</syntax>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick<contextlist><context>server config</context><context>virtual host</context>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick<context>directory</context><context>.htaccess</context>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick</contextlist>
367cefc17f8dcfe65651c9c16cb3151589c6cecetrawick<p>Invoke a lua function in the auth_checker phase of processing
367cefc17f8dcfe65651c9c16cb3151589c6cecetrawicka request. This can be used to implement arbitrary authentication
367cefc17f8dcfe65651c9c16cb3151589c6cecetrawickand authorization checking. A very simple example:
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowerequire 'apache2'
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe-- fake authcheck hook
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe-- If request has no auth info, set the response header and
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe-- return a 401 to ask the browser for basic auth info.
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj-- If request has auth info, don't actually look at it, just
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj-- pretend we got userid 'foo' and validated it.
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj-- Then check if the userid is 'foo' and accept the request.
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpjfunction authcheck_hook(r)
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe -- look for auth info
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe auth = r.headers_in['Authorization']
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe if auth ~= nil then
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe -- fake the user
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe if r.user == nil then
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe r:debug("authcheck: user is nil, returning 401")
e199d79647c689a85951f19b08a08082263f4df8brianp r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
e199d79647c689a85951f19b08a08082263f4df8brianp elseif r.user == "foo" then
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe r:debug('user foo: OK')
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe r:debug("authcheck: user='" .. r.user .. "'")
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe</directivesynopsis>
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe<directivesynopsis>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick<description>Provide a hook for the access_checker phase of request processing</description>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick<syntax>LuaHookAccessChecker /path/to/lua/script.lua hook_function_name</syntax>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick<contextlist><context>server config</context><context>virtual host</context>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick<context>directory</context><context>.htaccess</context>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick</contextlist>
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpj<p>Add your hook to the access_checker phase. An access checker
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpjhook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpj</directivesynopsis>
58eb8d7cca552570577aa8b636349a695ff193datrawick<directivesynopsis>
58eb8d7cca552570577aa8b636349a695ff193datrawick<description>Provide a hook for the insert_filter phase of request processing</description>
58eb8d7cca552570577aa8b636349a695ff193datrawick<syntax>LuaHookInsertFilter /path/to/lua/script.lua hook_function_name</syntax>
ecf435f0c6379df7ed83285d5597fc9aa39c6f6dbrianp<contextlist><context>server config</context><context>virtual host</context>
ecf435f0c6379df7ed83285d5597fc9aa39c6f6dbrianp<context>directory</context><context>.htaccess</context>
ecf435f0c6379df7ed83285d5597fc9aa39c6f6dbrianp</contextlist>
480f2a1b2fb27a8284e66e60a5bbaee6bc1ccb04trawick</directivesynopsis>
480f2a1b2fb27a8284e66e60a5bbaee6bc1ccb04trawick<directivesynopsis>
acc9093ae1f3c97acc635bd5b2c7c0969da21183trawick<description>Provide a hook for the quick handler of request processing</description>
2fa5f4c38890220c6ea439317e7dcb9e8b3c76f7jwoolley<contextlist><context>server config</context><context>virtual host</context>
2fa5f4c38890220c6ea439317e7dcb9e8b3c76f7jwoolley<context>directory</context><context>.htaccess</context>
2fa5f4c38890220c6ea439317e7dcb9e8b3c76f7jwoolley</contextlist>
95d00ea81131488769296fa5765ed745cbf45207trawick</directivesynopsis>
95d00ea81131488769296fa5765ed745cbf45207trawick</modulesynopsis>