mod_lua.xml revision 10961a2f60207cb873d889bb28b1f0ef707a4311
c30ef289fe64ac7fedc44cfcc6b439f0f8458b4cgregames<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
c30ef289fe64ac7fedc44cfcc6b439f0f8458b4cgregames<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
5541a81e194dc99521c0ecf904a940b0b65a93f2nd<!-- $LastChangedRevision$ -->
07342c358cd73b304b1991e359a3faf720c966ecnd Licensed to the Apache Software Foundation (ASF) under one or more
9556fb65eecaa55b866b413d5e262cd54be88f21nd contributor license agreements. See the NOTICE file distributed with
9556fb65eecaa55b866b413d5e262cd54be88f21nd this work for additional information regarding copyright ownership.
9556fb65eecaa55b866b413d5e262cd54be88f21nd The ASF licenses this file to You under the Apache License, Version 2.0
9556fb65eecaa55b866b413d5e262cd54be88f21nd (the "License"); you may not use this file except in compliance with
7d851311462dce44df8469009f98ba66d7f7f18end the License. You may obtain a copy of the License at
7d851311462dce44df8469009f98ba66d7f7f18end Unless required by applicable law or agreed to in writing, software
987c2c2ff2f19f306357f79d3280b347d96c470fnd distributed under the License is distributed on an "AS IS" BASIS,
987c2c2ff2f19f306357f79d3280b347d96c470fnd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
987c2c2ff2f19f306357f79d3280b347d96c470fnd See the License for the specific language governing permissions and
987c2c2ff2f19f306357f79d3280b347d96c470fnd limitations under the License.
0b0966806a96fd817692a5420908594a0c7f9f89trawick<description>Provides Lua hooks into various portions of the httpd
8eeb24cab1b849bd17726d0a030cd299209f108cndrequest processing</description>
7edcfe02796a70f2a5eac12b6766d11067c629a3rederpj<p>This module allows the server to be extended with scripts written in the
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpjLua programming language. The extension points (hooks) available with
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpj<module>mod_lua</module> include many of the hooks available to
c2d16e88f6a997b9174b5596db5e03cee5f46a8brederpjnatively compiled Apache HTTP Server modules, such as mapping requests to
a4dd3688dd6645faf0c1c1bfb22017c8f03d5b24ndfiles, generating dynamic responses, access control, authentication, and
a4dd3688dd6645faf0c1c1bfb22017c8f03d5b24ndauthorization</p>
a16ca336064074171bffc3a6da3444243a06b62btrawick<p>More information on the Lua programming language can be found at the
a16ca336064074171bffc3a6da3444243a06b62btrawick<a href="http://www.lua.org/">the Lua website</a>.</p>
f2fe083bb9fabd2af7eb39d4f154f27a451bb5a4nd<note><code>mod_lua</code> is still in experimental state.
f2fe083bb9fabd2af7eb39d4f154f27a451bb5a4ndUntil it is declared stable, usage and behavior may change
f2fe083bb9fabd2af7eb39d4f154f27a451bb5a4ndat any time, even between stable releases of the 2.4.x series.
f2fe083bb9fabd2af7eb39d4f154f27a451bb5a4ndBe sure to check the CHANGES file before upgrading.</note>
7de6cb79f71a9007ba2b1e786cbad8b84f05d101nd<p>This module holds a great deal of power over httpd, which is both a
7de6cb79f71a9007ba2b1e786cbad8b84f05d101ndstrength and a potential security risk. It is <strong>not</strong> recommended
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawickthat you use this module on a server that is shared with users you do not
aa9b03a5f32732c0caaef03a7ed78ffb290e29e4trawicktrust, as it can be abused to change the internal workings of httpd.</p>
a81c9e8561ebd18177a87fecf1226ac654b873f1rederpj<section id="basicconf"><title>Basic Configuration</title>
a3954060338ccebc73071e89ac936d4ec15ab352trawick</highlight>
ab56518227d474ee08f039e4c5540011c1b8a913trawick<code>mod_lua</code> provides a handler named <code>lua-script</code>,
ab56518227d474ee08f039e4c5540011c1b8a913trawickwhich can be used with an <code>AddHandler</code> directive:</p>
4e330708371c3e9b04d1043f0a1ac9368bfbd768coarAddHandler lua-script .lua
532a5de31e1a9732da4923f88e4931d0724ebe72nd</highlight>
219e31b849ef108cd8f58ba0eedae03414e5edb1thommayThis will cause <code>mod_lua</code> to handle requests for files
dbb916b882c33a4e340b0dba7d75506cfdd85640trawick<p>For more flexibility, see <directive>LuaMapHandler</directive>.
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawick<section id="writinghandlers"><title>Writing Handlers</title>
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawick<p> In the Apache HTTP Server API, the handler is a specific kind of hook
a18a308d7a942230edcde1bf00d7ae9b4b143c90trawickresponsible for generating the response. Examples of modules that include a
9efe68be3c81ee85225972195fb725dbfc2e8b24trawickhandler are <module>mod_proxy</module>, <module>mod_cgi</module>,
9098f795fab5db41a52b6b82fa475e8f9b3850f0trawick<p><code>mod_lua</code> always looks to invoke a Lua function for the handler, rather than
9efe68be3c81ee85225972195fb725dbfc2e8b24trawickjust evaluating a script body CGI style. A handler function looks
3b872593fd5f61981d9dd69a4b0b5d5f5f668929trawicksomething like this:</p>
fc25339741311efd7d460f18b6287ef38d76bbe6madhum-- example handler
fcdca175a52fe517f2317ba0e2b6e6d14522b869madhumrequire "string"
92a2439559cf1161742650ed9c50c6483bd029cemadhum This is the default method name for Lua handlers, see the optional
92a2439559cf1161742650ed9c50c6483bd029cemadhum function-name in the LuaMapHandler directive to choose a different
92a2439559cf1161742650ed9c50c6483bd029cemadhum entry point.
0d60370bedd05f9632f54e85c417ce472d463674madhumfunction handle(r)
764315969cef40e50cdc6a5e9638454e10c1c06end r:puts("Hello Lua World!\n")
764315969cef40e50cdc6a5e9638454e10c1c06end if r.method == 'GET' then
764315969cef40e50cdc6a5e9638454e10c1c06end for k, v in pairs( r:parseargs() ) do
bfb54bd96690887dcdf184fd9083c2e167898ce2nd r:puts( string.format("%s: %s\n", k, v) )
a2c036f0ca71e35c085b4cd9451a6d3718bc65daake elseif r.method == 'POST' then
a2c036f0ca71e35c085b4cd9451a6d3718bc65daake for k, v in pairs( r:parsebody() ) do
a2c036f0ca71e35c085b4cd9451a6d3718bc65daake r:puts( string.format("%s: %s\n", k, v) )
b92cba59a0890be43b14aaf1ce30606140be9593nd r:puts("Unsupported HTTP method " .. r.method)
402d23baca89e8c4fcb4e52ad8b2d66a6904baaetrawick</highlight>
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantzThis handler function just prints out the uri or form encoded
4caa28863a3418d26cc20a998dc368c3de3b7e19jerenkrantzarguments to a plaintext page.
9e398d701dd430f073ff5418fb720642e064046ajerenkrantzThis means (and in fact encourages) that you can have multiple
9e398d701dd430f073ff5418fb720642e064046ajerenkrantzhandlers (or hooks, or filters) in the same script.
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74nd<p><module>mod_authz_core</module> provides a high-level interface to
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74ndauthorization that is much easier to use than using into the relevant
ba6c07204bd224fa5d4cd0e6b8bf256d6daffb74ndhooks directly. The first argument to the
db5837bbc9bef214303e755fa52122140366cb6fianh<directive module="mod_authz_core">Require</directive> directive gives
db5837bbc9bef214303e755fa52122140366cb6fianhthe name of the responsible authorization provider. For any
db5837bbc9bef214303e755fa52122140366cb6fianh<directive module="mod_authz_core">Require</directive> line,
aac2b82fe4f1ac117e2a0702438d6615542642dand<module>mod_authz_core</module> will call the authorization provider
aac2b82fe4f1ac117e2a0702438d6615542642dandof the given name, passing the rest of the line as parameters. The
aac2b82fe4f1ac117e2a0702438d6615542642dandprovider will then check authorization and pass the result as return
0a209fcb17b8c9a42a6149a1758e61cf6527d367nd<p>The authz provider is normally called before authentication. If it needs to
a793d402c74e50326a2401cfbdc562c5781948fdndknow the authenticated user name (or if the user will be authenticated at
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzall), the provider must return <code>apache2.AUTHZ_DENIED_NO_USER</code>.
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzThis will cause authentication to proceed and the authz provider to be
99d360dcbb5ac2be27694be74cc6124dbadf3315jerenkrantzcalled a second time.</p>
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantz<p>The following authz provider function takes two arguments, one ip
3ded62d7f2c9b12616d718b8c97d3044baa9ecdbjerenkrantzaddress and one user name. It will allow access from the given ip address
ab8c0315521735c73ce16c8072f91e17c406ca5bndwithout authentication, or if the authenticated user matches the second
ab8c0315521735c73ce16c8072f91e17c406ca5bndargument:</p>
b9e99e0d3154bbebe3e1b8d11d6c15bde79510a5ndrequire 'apache2'
ea5f8cfbb7ef1d19318f6994c26dd73c38ffd8ddjerenkrantzfunction authz_check_foo(r, ip, user)
4567cfc6a65328bd3e8dd2b758ca926b389c7058brianp elseif r.user == nil then
4cdc5446050c19b9d519a273a129188586e8d445jerenkrantz elseif r.user == user then
2f408250e9111c4b85b2b4b9b8836e83987efdefstoddard</highlight>
47fe07199bddec6124ab7251c6be5c6c9ac00485jerenkrantz<p>The following configuration registers this function as provider
47fe07199bddec6124ab7251c6be5c6c9ac00485jerenkrantz<code>foo</code> and configures it for URL <code>/</code>:</p>
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantzLuaAuthzProvider foo authz_provider.lua authz_check_foo
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz<Location />
6646a289c2d4778c8cd43d62b5a1cc966a356f85jerenkrantz Require foo 10.1.2.3 john_doe
aec70520ebe1e33e0d5e83c3626649d2a41dbe68wrowe</Location>
aec70520ebe1e33e0d5e83c3626649d2a41dbe68wrowe</highlight>
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe<section id="writinghooks"><title>Writing Hooks</title>
59b910556d04c82e951d6c6f7a413ab8fed21467trawick<p>Hook functions are how modules (and Lua scripts) participate in the
59b910556d04c82e951d6c6f7a413ab8fed21467trawickprocessing of requests. Each type of hook exposed by the server exists for
5c457d20a708ef42b0824290d0feda1852a37493rederpja specific purposes such as mapping requests to the filesystem,
5c457d20a708ef42b0824290d0feda1852a37493rederpjperforming access control, or setting mimetypes:</p>
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd <td><directive module="mod_lua">LuaQuickHandler</directive></td>
cde00ab9085ea6e93db4a27bf6fe9a9b6eda4addnd <td>This is the first hook that will be called after a request has
159d95df05b3100bbef7a60cb5f5d7d8d5a3328etrawick been mapped to a host or virtual host</td>
59b910556d04c82e951d6c6f7a413ab8fed21467trawick <td><directive module="mod_lua">LuaHookTranslateName</directive></td>
59b910556d04c82e951d6c6f7a413ab8fed21467trawick <td>This phase translates the requested URI into a filename on the
59b910556d04c82e951d6c6f7a413ab8fed21467trawick system. Modules such as <module>mod_alias</module> and
59b910556d04c82e951d6c6f7a413ab8fed21467trawick <module>mod_rewrite</module> operate in this phase.</td>
03e310ef946842b4dfa718776c870d012fc9ec67striker <td><directive module="mod_lua">LuaHookMapToStorage</directive></td>
03e310ef946842b4dfa718776c870d012fc9ec67striker <td>This phase maps files to their physical, cached or external/proxied storage.
03e310ef946842b4dfa718776c870d012fc9ec67striker It can be used by proxy or caching modules</td>
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker <td><directive module="mod_lua">LuaHookAccessChecker</directive></td>
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker <td>This phase checks whether a client has access to a resource. This
611d2f4e86b4eceb640a5301bd88a23cb459e5a8striker phase is run before the user is authenticated, so beware.
f59888906d0566361498848fa95b4c416fad976cstriker <td><directive module="mod_lua">LuaHookCheckUserID</directive></td>
f59888906d0566361498848fa95b4c416fad976cstriker <td>This phase it used to check the negotiated user ID</td>
6a3078c438bee65f22004ac65cd2eb4fa521bbfastriker <td><directive module="mod_lua">LuaHookAuthChecker</directive> or
6a3078c438bee65f22004ac65cd2eb4fa521bbfastriker <directive module="mod_lua">LuaAuthzProvider</directive></td>
26acc990e97a62631a3654405d676b928a78ebbcstriker <td>This phase authorizes a user based on the negotiated credentials, such as
26acc990e97a62631a3654405d676b928a78ebbcstriker user ID, client certificate etc.
29ecc0949b383793b24cdd0741cb86c02138ab36striker <td><directive module="mod_lua">LuaHookTypeChecker</directive></td>
29ecc0949b383793b24cdd0741cb86c02138ab36striker <td>This phase checks the requested file and assigns a content type and
c97f8ff3a7479c838545de0c59770938b50ab6d3gstein a handler to it</td>
6fb9d10c529c2be3bb1833b0eefdd27ba4df1610trawick <td><directive module="mod_lua">LuaHookFixups</directive></td>
6fb9d10c529c2be3bb1833b0eefdd27ba4df1610trawick <td>This is the final "fix anything" phase before the content handlers
6fb9d10c529c2be3bb1833b0eefdd27ba4df1610trawick are run. Any last-minute changes to the request should be made here.</td>
368a950bc36b428b737d079f77e8962c831f88aand <td>fx. <code>.lua</code> files or through <directive module="mod_lua">LuaMapHandler</directive></td>
368a950bc36b428b737d079f77e8962c831f88aand <td>This is where the content is handled. Files are read, parsed, some are run,
368a950bc36b428b737d079f77e8962c831f88aand and the result is sent to the client</td>
9768955299008e29705461b314b763a79104e576nd <td>Once a request has been handled, it enters several logging phases,
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc which logs the request in either the error or access log</td>
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc<p>Hook functions are passed the request object as their only argument
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjc(except for LuaAuthzProvider, which also gets passed the arguments from
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjcthe Require directive).
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjcThey can return any value, depending on the hook, but most commonly
1005ad40d72c4a1df2c0f1b95b770a4c43c49a47mjcthey'll return OK, DONE, or DECLINED, which you can write in lua as
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz<code>apache2.DECLINED</code>, or else an HTTP status code.</p>
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantz-- example hook that rewrites the URI to a filesystem path.
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantzrequire 'apache2'
da5a84048552168ea64c3012573acd4de1434dcdjerenkrantzfunction translate_name(r)
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz if r.uri == "/translate-name" then
19fdbc5566bf67dde644be9e8d38d62db4dd0ba5jerenkrantz -- we don't care about this URL, give another module a chance
e874834efe9943668668c7fa498af3b3c7caffbdnd--[[ example hook that rewrites one URI to another URI. It returns a
e874834efe9943668668c7fa498af3b3c7caffbdnd apache2.DECLINED to give other URL mappers a chance to work on the
e874834efe9943668668c7fa498af3b3c7caffbdnd substitution, including the core translate_name hook which maps based
e874834efe9943668668c7fa498af3b3c7caffbdnd on the DocumentRoot.
b617020883fa3b18bc9b5be5e896ceed79a7ff7fnd Note: Use the early/late flags in the directive to make it run before
b617020883fa3b18bc9b5be5e896ceed79a7ff7fnd or after mod_alias.
38873f61704cbe5eadaa3fb9dca84a4bee1ae5d5wrowerequire 'apache2'
38873f61704cbe5eadaa3fb9dca84a4bee1ae5d5wrowefunction translate_name(r)
68a80326bd8b6f717ae0c44d4bb7273023aad1edwrowe if r.uri == "/translate-name" then
6838d0e05a193cb77265db36e3549201b3df57e6wrowe</highlight>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe<section id="datastructures"><title>Data Structures</title>
732269e2780cb818c1b48aeffa0b432b0ce4ee5eaaron <p>The request_rec is mapped in as a userdata. It has a metatable
732269e2780cb818c1b48aeffa0b432b0ce4ee5eaaron which lets you do useful things with it. For the most part it
20aa030accab9a4df293294283fbe6a4ae961588trawick has the same fields as the request_rec struct, many of which are writeable as
20aa030accab9a4df293294283fbe6a4ae961588trawick well as readable. (The table fields' content can be changed, but the
20aa030accab9a4df293294283fbe6a4ae961588trawick fields themselves cannot be set to different tables.)</p>
16de8ff78c533f06c64d5ab2b685953992ff8659thommay <td>The AllowOverride options applied to the current request.</td>
340e970018246649e86dd3ebbd34f4719e3ceaf7trawick <td>If an authentication check was made, this is set to the type
1360e9b0036040edfbcd2273ae18db83a93536detrawick <td>The query string arguments extracted from the request
c3f32ea297c5350948a0c4472c1ff8433ea4e6bastoddard (e.g. <code>GET /foo</code> (with no headers) )</td>
8c038cdb417502a969599568ccc4020576d82a10nd <td>The realm name used for authorization (if applicable).</td>
8c038cdb417502a969599568ccc4020576d82a10nd <td>The server banner, f.x. <code>Apache HTTP Server/2.4.3 openssl/0.9.8c</code></td>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe <td>The basic auth password sent with this request, if any</td>
c8ff8621370eb28a3f697a00bf5e6b3bc1a0d9f1minfrin <td>The content encoding of the current request</td>
97610ac677a5eda4a3bb366c5bb34a27eeb4288cminfrin <td>The content type of the current request, as determined in the
97610ac677a5eda4a3bb366c5bb34a27eeb4288cminfrin type_check phase (f.x. <code>image/gif</code> or <code>text/html</code>)</td>
6aa783d83f4304f664233d8252cb67116769676ewrowe <td>MIME header environment for the response, printed even on errors and
6aa783d83f4304f664233d8252cb67116769676ewrowe persist across internal redirects</td>
f1e73dbab9ba73d83c9ac8a13ab6150653bb71a9brianp <td>The file name that the request maps to, f.x. /www/example.com/foo.txt. This can be
f1e73dbab9ba73d83c9ac8a13ab6150653bb71a9brianp changed in the translate-name or map-to-storage phases of a request to allow the
7a01bcd2d59be7ec9ce55701c58054fa1c0bb5b6wrowe default handler (or script handlers) to serve a different file than what was requested.</td>
9d71a9210ee030534400d37010f34e6a7d72b53fnd <td>The name of the <a href="/handler.html">handler</a> that should serve this request, f.x.
9d71a9210ee030534400d37010f34e6a7d72b53fnd <code>lua-script</code> if it is to be served by mod_lua. This is typically set by the
9d71a9210ee030534400d37010f34e6a7d72b53fnd <directive module="mod_mime">AddHandler</directive> or <directive module="core">SetHandler</directive>
9d71a9210ee030534400d37010f34e6a7d72b53fnd directives, but could also be set via mod_lua to allow another handler to serve up a specific request
5d6ffa7b5c77dd4132ed6d7f0dd63548b1c3c1c9nd that would otherwise not be served by it.
74b84dd6e146edc93cf1b3200e411bfc581f7c36nd <td>MIME header environment from the request. This contains headers such as <code>Host,
7a2b9ea4788ea59d81b9e84192e4b90a9a0da875wrowe <td>The host name, as set by the <code>Host:</code> header or by a full URI.</td>
70f28b17978da5478a97843ab7cbcb4baf7a8711nd <td>Whether this request is the initial request or a sub-request</td>
f5208b93c14accca0cd5f5acb042332b20172fb1nd <td>The size limit of the request body for this request, or 0 if no limit.</td>
1125f364c5cb4fd9bff71e89b5d4cbf551590035bnicholes <td>The ID to identify request in access and error log.</td>
9d999c5deeddad9211695fc736a845afda6a2e95wrowe <td>The request method, f.x. <code>GET</code> or <code>POST</code>.</td>
f19141958ebbfa8feb78e27007b4023d710d1c7etrawick <td>A list of notes that can be passed on from one module to another.</td>
c5c445b5614e4d5040d3c0994d2456f1ac8cb9b5jerenkrantz <td>The Options directive applied to the current request.</td>
f16b2c3124a11bff93724342099e1afdb8145917bnicholes <td>The protocol used, f.x. <code>HTTP/1.1</code></td>
d584e3b7a33da68233e7ac403213b436b402f5bend <td>Denotes whether this is a proxy request or not. This value is generally set in
d584e3b7a33da68233e7ac403213b436b402f5bend the post_read_request/translate_name phase of a request.</td>
d584e3b7a33da68233e7ac403213b436b402f5bend <td>The number of bytes remaining to be read from the request body.</td>
965680cd7c050ec8c8c751ffdbaf19c91213d562trawick <td>Whether some authorization is/was required for this request.</td>
52d61f96a186861d991583851218e15ea16f0abetrawick <td>The environment variables set for this request.</td>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe <td>The time the server was (re)started, in seconds since the epoch (Jan 1st, 1970)</td>
11e365512cbf021726cd3ec3d80743f408170ff9stoddard <td>The (current) HTTP return code for this request, f.x. <code>200</code> or <code>404</code>.</td>
2774f23eee36fdb1b30a8213bbcabe5336175e54jwoolley <td>The request string as sent by the client, f.x. <code>GET /foo/bar HTTP/1.1</code>.</td>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick <td>If an authentication check has been made, this is set to the name of the authenticated user.</td>
f9a987f71572291f35b9d0adc3fe79af96b2b147trawick <td>The IP of the user agent making the request</td>
5c870e08d589a24283cd76a9d596120605762cbbminfrin <p>The request_rec has (at least) the following methods:</p>
47d4dfaca60aff6d3c7e591bf593b3961cafcdefminfrin r:flush() -- flushes the output buffer
47d4dfaca60aff6d3c7e591bf593b3961cafcdefminfrin </highlight>
c206205e2475a7a4a192eaa7190a9894f01f0631minfrin r:addoutputfilter(name|function) -- add an output filter
c206205e2475a7a4a192eaa7190a9894f01f0631minfrin </highlight>
304aee4b1ff85cc876570493e4ed334d42b4d9eftrawick r:sendfile(filename) -- sends an entire file to the client, using sendfile if supported by the current platform
304aee4b1ff85cc876570493e4ed334d42b4d9eftrawick </highlight>
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick r:parseargs() -- returns a Lua table containing the request's query string arguments
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick </highlight>
77582a85f880a10e8e225ecd5b303446d23d1c9atrawick r:parsebody() -- parse any POST data in the request and return it as a Lua table
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe </highlight>
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe r:puts("hello", " world", "!") -- print to response body
111b2312c9749936ebca4f273db445820a0a703ebrianp </highlight>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick r:write("a single string") -- print to response body
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick </highlight>
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick r:escape_html("<html>test</html>") -- Escapes HTML code and returns the escaped result
ad877cddc14be8c8171938ba61338c6c7b896bbdtrawick </highlight>
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe -- examples of logging messages<br />
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe r:trace1("This is a trace log message") -- trace1 through trace8 can be used <br />
f49cf8ce86a01c90d5d843fc27e19d2802dd0f77wrowe r:debug("This is a debug log message")<br />
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj r:info("This is an info log message")<br />
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj r:notice("This is an notice log message")<br />
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj r:warn("This is an warn log message")<br />
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj r:err("This is an err log message")<br />
9b867bfaea269f387a0cf2aa4c9f38d4d51bac94rederpj r:alert("This is an alert log message")<br />
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe r:crit("This is an crit log message")<br />
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe r:emerg("This is an emerg log message")<br />
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe</highlight>
52435ceaabd1670b2c3a062acc191159a64fb7a1wrowe<p>A package named <code>apache2</code> is available with (at least) the following contents.</p>
e199d79647c689a85951f19b08a08082263f4df8brianp <dd>internal constant OK. Handlers should return this if they've
e199d79647c689a85951f19b08a08082263f4df8brianp handled the request.</dd>
6838d0e05a193cb77265db36e3549201b3df57e6wrowe <dd>internal constant DECLINED. Handlers should return this if
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe they are not going to handle the request.</dd>
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe <dt>apache2.PROXYREQ_NONE, apache2.PROXYREQ_PROXY, apache2.PROXYREQ_REVERSE, apache2.PROXYREQ_RESPONSE</dt>
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe <dd>internal constants used by <module>mod_proxy</module></dd>
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe <dt>apache2.AUTHZ_DENIED, apache2.AUTHZ_GRANTED, apache2.AUTHZ_NEUTRAL, apache2.AUTHZ_GENERAL_ERROR, apache2.AUTHZ_DENIED_NO_USER</dt>
ad451e2e428a069086d1c18c9e3372f8846ec617wrowe <dd>internal constants used by <module>mod_authz_core</module></dd>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick<p>(Other HTTP status codes are not yet implemented.)</p>
1e1e5c477f92840ffbcb8acd0003305022e5468atrawick<directivesynopsis>
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpj<description>Specify the base path for resolving relative paths for mod_lua directives</description>
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpj<contextlist><context>server config</context><context>virtual host</context>
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpj<context>directory</context><context>.htaccess</context>
c998c5be82bf2b41f8fc27de9376ba10651c74bcrederpj</contextlist>
58eb8d7cca552570577aa8b636349a695ff193datrawick <p>Specify the base path which will be used to evaluate all
58eb8d7cca552570577aa8b636349a695ff193datrawick relative paths within mod_lua. If not specified they
ecf435f0c6379df7ed83285d5597fc9aa39c6f6dbrianp will be resolved relative to the current working directory,
ecf435f0c6379df7ed83285d5597fc9aa39c6f6dbrianp which may not always work well for a server.</p>
ecf435f0c6379df7ed83285d5597fc9aa39c6f6dbrianp</directivesynopsis>
480f2a1b2fb27a8284e66e60a5bbaee6bc1ccb04trawick<directivesynopsis>
480f2a1b2fb27a8284e66e60a5bbaee6bc1ccb04trawick<description>One of once, request, conn, thread -- default is once</description>
acc9093ae1f3c97acc635bd5b2c7c0969da21183trawick<syntax>LuaScope once|request|conn|thread|server [min] [max]</syntax>
acc9093ae1f3c97acc635bd5b2c7c0969da21183trawick<contextlist><context>server config</context><context>virtual host</context>
2fa5f4c38890220c6ea439317e7dcb9e8b3c76f7jwoolley<context>directory</context><context>.htaccess</context>
2fa5f4c38890220c6ea439317e7dcb9e8b3c76f7jwoolley</contextlist>
95d00ea81131488769296fa5765ed745cbf45207trawick <p>Specify the lifecycle scope of the Lua interpreter which will
95d00ea81131488769296fa5765ed745cbf45207trawick be used by handlers in this "Directory." The default is "once"</p>
95d00ea81131488769296fa5765ed745cbf45207trawick <dt>once:</dt> <dd>use the interpreter once and throw it away.</dd>
f08574f1098defdf1dc7e7f18a1e3664ee157150rederpj <dt>request:</dt> <dd>use the interpreter to handle anything based on
f08574f1098defdf1dc7e7f18a1e3664ee157150rederpj the same file within this request, which is also
f08574f1098defdf1dc7e7f18a1e3664ee157150rederpj request scoped.</dd>
f08574f1098defdf1dc7e7f18a1e3664ee157150rederpj <dt>conn:</dt> <dd>Same as request but attached to the connection_rec</dd>
f08574f1098defdf1dc7e7f18a1e3664ee157150rederpj <dt>thread:</dt> <dd>Use the interpreter for the lifetime of the thread
f08574f1098defdf1dc7e7f18a1e3664ee157150rederpj handling the request (only available with threaded MPMs).</dd>
84854ca5d35fb9f101da948858097c88457eece8coar <dt>server:</dt> <dd>This one is different than others because the
84854ca5d35fb9f101da948858097c88457eece8coar server scope is quite long lived, and multiple threads
84854ca5d35fb9f101da948858097c88457eece8coar will have the same server_rec. To accommodate this,
84854ca5d35fb9f101da948858097c88457eece8coar server scoped Lua states are stored in an apr
30990c446eca5b0d16d42171a6b30da9456ff6b4trawick resource list. The <code>min</code> and <code>max</code> arguments
30990c446eca5b0d16d42171a6b30da9456ff6b4trawick specify the minimum and maximum number of Lua states to keep in the
0fd9de72e2a1be5a6134ee70703324be80d816b7trawick Generally speaking, the <code>thread</code> and <code>server</code> scopes
0fd9de72e2a1be5a6134ee70703324be80d816b7trawick execute roughly 2-3 times faster than the rest, because they don't have to
2213cc395cb461faf7bfeb187ebb61d97cd457efjerenkrantz spawn new Lua states on every request (especially with the event MPM, as
f36d2c405b5a9bcc22c67577995560e7d1b616c0aaron even keepalive requests will use a new thread for each request). If you are
2213cc395cb461faf7bfeb187ebb61d97cd457efjerenkrantz satisfied that your scripts will not have problems reusing a state, then
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe the <code>thread</code> or <code>server</code> scopes should be used for
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe maximum performance. While the <code>thread</code> scope will provide the
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe fastest responses, the <code>server</code> scope will use less memory, as
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe states are pooled, allowing f.x. 1000 threads to share only 100 Lua states,
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe thus using only 10% of the memory required by the <code>thread</code> scope.
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe</directivesynopsis>
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe<directivesynopsis>
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe<syntax>LuaMapHandler uri-pattern /path/to/lua/script.lua [function-name]</syntax>
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe<contextlist><context>server config</context><context>virtual host</context>
854c7bc4128fa2ad9fdfe0fc307d5ef30bcb5bb9wrowe<context>directory</context><context>.htaccess</context>
75f8e1cae5ca3a16a7400cdddf604815ab06b5a8rederpj</contextlist>
75f8e1cae5ca3a16a7400cdddf604815ab06b5a8rederpj <p>This directive matches a uri pattern to invoke a specific
75f8e1cae5ca3a16a7400cdddf604815ab06b5a8rederpj handler function in a specific file. It uses PCRE regular
75f8e1cae5ca3a16a7400cdddf604815ab06b5a8rederpj expressions to match the uri, and supports interpolating
75f8e1cae5ca3a16a7400cdddf604815ab06b5a8rederpj match groups into both the file path and the function name.
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe Be careful writing your regular expressions to avoid security
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe issues.</p>
d8f54fe5534b61afa68100dddbe2eb98285d1100wrowe LuaMapHandler /(\w+)/(\w+) /scripts/$1.lua handle_$2
7f481efe04fdc4da7a447c14be62c155cbe00ddbbrianp </highlight>
9ed34e5219ab3506ccfd2ca58751ce4c81b263a8rederpj handler function handle_show on the lua vm after
9ed34e5219ab3506ccfd2ca58751ce4c81b263a8rederpj loading that file.</p>
23b36269d124e7a6aaa5221891f7ae2ef3eeb158jerenkrantz <p>This would invoke the "handle" function, which
d401ff3af66624a7023460054519070a025d31cfwrowe is the default if no specific function name is
d401ff3af66624a7023460054519070a025d31cfwrowe provided.</p>
d401ff3af66624a7023460054519070a025d31cfwrowe</directivesynopsis>
e65b56dc229f063425fac589002e34c8246ad878trawick<directivesynopsis>
e65b56dc229f063425fac589002e34c8246ad878trawick<description>Add a directory to lua's package.path</description>
306bd64cf6568149964abdf8ca748a617ed98500gregames<syntax>LuaPackagePath /path/to/include/?.lua</syntax>
306bd64cf6568149964abdf8ca748a617ed98500gregames<contextlist><context>server config</context><context>virtual host</context>
306bd64cf6568149964abdf8ca748a617ed98500gregames<context>directory</context><context>.htaccess</context>
5bd562b1d7da51cb5715899d32bb4c79c54459b0wrowe</contextlist>
ae3d212043d50288748fe9fdf0aa1a3e8f2ff3a6wrowe <usage><p>Add a path to lua's module search path. Follows the same
ae3d212043d50288748fe9fdf0aa1a3e8f2ff3a6wrowe conventions as lua. This just munges the package.path in the
ae3d212043d50288748fe9fdf0aa1a3e8f2ff3a6wrowe lua vms.</p>
766c20b0366e1d0e359e0d9a834669e19a4db3d9trawick </highlight>
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar</directivesynopsis>
2a6e98ba4ffa30ded5d8831664c5cb2a170a56b6coar<directivesynopsis>
9a11fa4e07f50f2e5750d078ef3751ddbf441b8ftrawick<description>Add a directory to lua's package.cpath</description>
9a11fa4e07f50f2e5750d078ef3751ddbf441b8ftrawick<syntax>LuaPackageCPath /path/to/include/?.soa</syntax>
1f279dc92a60df9f61bf58468162aab0eef072e4brianp<contextlist><context>server config</context><context>virtual host</context>
1f279dc92a60df9f61bf58468162aab0eef072e4brianp<context>directory</context><context>.htaccess</context>
1f279dc92a60df9f61bf58468162aab0eef072e4brianp</contextlist>
2fd0edbd8b2f47a8458322bedd3b82f825faf336trawick <p>Add a path to lua's shared library search path. Follows the same
39021cf8b495cdb94013ca73531ccb32658fb793rederpj conventions as lua. This just munges the package.cpath in the
39021cf8b495cdb94013ca73531ccb32658fb793rederpj lua vms.</p>
39021cf8b495cdb94013ca73531ccb32658fb793rederpj</directivesynopsis>
39021cf8b495cdb94013ca73531ccb32658fb793rederpj<directivesynopsis>
fa16f10bc02e46bc5a6c2c2c6371926cd1dbe2edwrowe<description>Configure the compiled code cache.</description>
fa16f10bc02e46bc5a6c2c2c6371926cd1dbe2edwrowe<contextlist>
fa16f10bc02e46bc5a6c2c2c6371926cd1dbe2edwrowe<context>server config</context><context>virtual host</context>
fa16f10bc02e46bc5a6c2c2c6371926cd1dbe2edwrowe<context>directory</context><context>.htaccess</context>
fa16f10bc02e46bc5a6c2c2c6371926cd1dbe2edwrowe</contextlist>
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim Specify the behavior of the in-memory code cache. The default
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim is stat, which stats the top level script (not any included
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim ones) each time that file is needed, and reloads it if the
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim modified time indicates it is newer than the one it has
db8ac7cbb1fa6cdd6abcc4bb797d4deed32dd269jim already loaded. The other values cause it to keep the file
7b979864a91b52ecebca11d0a9a22e09349e59baminfrin cached forever (don't stat and replace) or to never cache the
7b979864a91b52ecebca11d0a9a22e09349e59baminfrin <p>In general stat or forever is good for production, and stat or never
7b979864a91b52ecebca11d0a9a22e09349e59baminfrin for development.</p>
1bae4591a85d90325ecdacedf7e54d1bbfe31037aaronLuaCodeCache stat
1bae4591a85d90325ecdacedf7e54d1bbfe31037aaronLuaCodeCache forever
1bae4591a85d90325ecdacedf7e54d1bbfe31037aaronLuaCodeCache never
a6f48cc01ab8f5377e570c61826dcdfc36741936trawick </highlight>
2da345202997f8f5860c801d68f7913c02fc05fctrawick</directivesynopsis>
2da345202997f8f5860c801d68f7913c02fc05fctrawick<directivesynopsis>
5bd562b1d7da51cb5715899d32bb4c79c54459b0wrowe<description>Provide a hook for the translate name phase of request processing</description>
5bd562b1d7da51cb5715899d32bb4c79c54459b0wrowe<syntax>LuaHookTranslateName /path/to/lua/script.lua hook_function_name [early|late]</syntax>
1c06e98017400874d5ff6ad79f13145ec4589225striker<contextlist><context>server config</context><context>virtual host</context>
1c06e98017400874d5ff6ad79f13145ec4589225striker</contextlist>
99a041314eb3db0b0cca325c9c40d0a6c5fdf04fwrowe<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
99a041314eb3db0b0cca325c9c40d0a6c5fdf04fwrowe Add a hook (at APR_HOOK_MIDDLE) to the translate name phase of
99a041314eb3db0b0cca325c9c40d0a6c5fdf04fwrowe request processing. The hook function receives a single
99a041314eb3db0b0cca325c9c40d0a6c5fdf04fwrowe argument, the request_rec, and should return a status code,
99a041314eb3db0b0cca325c9c40d0a6c5fdf04fwrowe which is either an HTTP error code, or the constants defined
99a041314eb3db0b0cca325c9c40d0a6c5fdf04fwrowe in the apache2 module: apache2.OK, apache2.DECLINED, or
6e119e632566d69798ce6cf4e714ed374b72914frederpj <p>For those new to hooks, basically each hook will be invoked
6e119e632566d69798ce6cf4e714ed374b72914frederpj until one of them returns apache2.OK. If your hook doesn't
6e119e632566d69798ce6cf4e714ed374b72914frederpj want to do the translation it should just return
bd120542ebe7e09cdbada5daf4924f4690e5ece3trawick apache2.DECLINED. If the request should stop processing, then
68d439bc0482b2e41053480f748edc2574c2ea7btrawickLuaHookTranslateName /scripts/conf/hooks.lua silly_mapper
68d439bc0482b2e41053480f748edc2574c2ea7btrawick</highlight>
a5ca705e053a6c754c5958aafcd6f0aa60a2e67frbbrequire "apache2"
e06675c51d084791089d79c3ac18aeae8dd465fcrbbfunction silly_mapper(r)
e06675c51d084791089d79c3ac18aeae8dd465fcrbb if r.uri == "/" then
a964f7434f5c7f512a5fa0d0178260ccb74c84berbb</highlight>
a964f7434f5c7f512a5fa0d0178260ccb74c84berbb <note><title>Context</title><p>This directive is not valid in <directive
6a7877447bcb8e6ff848d72f82f184c404ef4c0bminfrin type="section" module="core">Directory</directive>, <directive
6a7877447bcb8e6ff848d72f82f184c404ef4c0bminfrin type="section" module="core">Files</directive>, or htaccess
9335cbd541cca1ca6038af329bbd1645310aabccminfrin <note><title>Ordering</title><p>The optional arguments "early" or "late"
9335cbd541cca1ca6038af329bbd1645310aabccminfrin control when this script runs relative to other modules.</p></note>
9335cbd541cca1ca6038af329bbd1645310aabccminfrin</directivesynopsis>
9335cbd541cca1ca6038af329bbd1645310aabccminfrin<directivesynopsis>
e156db58351d1c040bc72430f3eb072cb6ae7107brianp<description>Provide a hook for the fixups phase of a request
e156db58351d1c040bc72430f3eb072cb6ae7107brianpprocessing</description>
e156db58351d1c040bc72430f3eb072cb6ae7107brianp<syntax>LuaHookFixups /path/to/lua/script.lua hook_function_name</syntax>
1c06e98017400874d5ff6ad79f13145ec4589225striker<contextlist><context>server config</context><context>virtual host</context>
1c06e98017400874d5ff6ad79f13145ec4589225striker<context>directory</context><context>.htaccess</context>
1c06e98017400874d5ff6ad79f13145ec4589225striker</contextlist>
6a94da925498a20a09fde0a66002607be8d83b1astriker Just like LuaHookTranslateName, but executed at the fixups phase
8dc5aa056a586ffa920a6ecd5c31048702371ea6brianp</directivesynopsis>
4c9d27bfdfea41b388dc705f7cc2b49318ab5344jim<directivesynopsis>
e8e8ab3cbc3d90f15eb78e094c381a6e908fd6efjerenkrantz<description>Provide a hook for the map_to_storage phase of request processing</description>
e8e8ab3cbc3d90f15eb78e094c381a6e908fd6efjerenkrantz<syntax>LuaHookMapToStorage /path/to/lua/script.lua hook_function_name</syntax>
e8e8ab3cbc3d90f15eb78e094c381a6e908fd6efjerenkrantz<contextlist><context>server config</context><context>virtual host</context>
f4c472b8dce3c2e559232dbb5b27ed2466922ea4jerenkrantz<context>directory</context><context>.htaccess</context>
f4c472b8dce3c2e559232dbb5b27ed2466922ea4jerenkrantz</contextlist>
8dc5aa056a586ffa920a6ecd5c31048702371ea6brianp <p>Like <directive>LuaHookTranslateName</directive> but executed at the
7e31ef4870c7ef94838585004405e8854fefcc51ianh map-to-storage phase of a request. Modules like mod_cache run at this phase,
7e31ef4870c7ef94838585004405e8854fefcc51ianh which makes for an interesting example on what to do here:</p>
7e31ef4870c7ef94838585004405e8854fefcc51ianh LuaHookMapToStorage /path/to/lua/script.lua check_cache
7e31ef4870c7ef94838585004405e8854fefcc51ianh </highlight>
bd496a3a7752a55c849e62ed00cacc492d4f6d3erederpjrequire"apache2"
bd496a3a7752a55c849e62ed00cacc492d4f6d3erederpjcached_files = {}
bd496a3a7752a55c849e62ed00cacc492d4f6d3erederpjfunction read_file(filename)
a8c401eadf77822e851f19c7740e7ec6dca03daastoddard local input = io.open(filename, "r")
a8c401eadf77822e851f19c7740e7ec6dca03daastoddard if input then
a8c401eadf77822e851f19c7740e7ec6dca03daastoddard local data = input:read("*a")
a8c401eadf77822e851f19c7740e7ec6dca03daastoddard cached_files[filename] = data
93d7153aa172665f55b04463b831ad556269c3efbrianp file = cached_files[filename]
791781f2ccc1f1f1bc1b1643861d3da23edfd147jerenkrantz input:close()
2ffa5829cad36f12b0a1fc3481592e85bc210a5bjerenkrantz return cached_files[filename]
02e8590d904653a95eca31bdf8e60866642bb592slivefunction check_cache(r)
02e8590d904653a95eca31bdf8e60866642bb592slive if r.filename:match("%.png$") then -- Only match PNG files
30a5ee06ae5f7f67a83d6852871f654ae3e14aadslive local file = cached_files[r.filename] -- Check cache entries
02e8590d904653a95eca31bdf8e60866642bb592slive if not file then
a97c4ce2bea3dbf8ddc82c796cf93aa6b46765a4brianp file = read_file(r.filename) -- Read file into cache
a97c4ce2bea3dbf8ddc82c796cf93aa6b46765a4brianp if file then -- If file exists, write it out
b7838ae85a698af19d90ba4ebe03e10bdc149eacjerenkrantz r:write(file)
435d2db95b905b0d16d35410e18ff77dc39688aabrianp r:info(("Sent %s to client from cache"):format(r.filename))
435d2db95b905b0d16d35410e18ff77dc39688aabrianp return apache2.DONE -- skip default handler for PNG files
a574815e2c6db68b9d8139db89921ededf033decianh return apache2.DECLINED -- If we had nothing to do, let others serve this.
964f539e766a3301b3e2f767baeffddcf9f6092bjerenkrantz </highlight>
5e538c6ced13aa2f7c358e1a44f651d31dd5fab8brianp</directivesynopsis>
5e538c6ced13aa2f7c358e1a44f651d31dd5fab8brianp<directivesynopsis>
61202a45487668abad788c02e339f626176e645fianh<description>Provide a hook for the check_user_id phase of request processing</description>
61202a45487668abad788c02e339f626176e645fianh<syntax>LuaHookCheckUserID /path/to/lua/script.lua hook_function_name [early|late]</syntax>
61202a45487668abad788c02e339f626176e645fianh<contextlist><context>server config</context><context>virtual host</context>
02c49e1f35a4d1a171df2d319e76af0c5163dc4dmartin<context>directory</context><context>.htaccess</context>
02c49e1f35a4d1a171df2d319e76af0c5163dc4dmartin</contextlist>
6deb8bcfb8511ac38243a8274fc589842841b398ianh<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
6deb8bcfb8511ac38243a8274fc589842841b398ianh <note><title>Ordering</title><p>The optional arguments "early" or "late"
49bbbd1939208be54a3eb00b95e61d90d180a606ianh control when this script runs relative to other modules.</p></note>
93d7153aa172665f55b04463b831ad556269c3efbrianp</directivesynopsis>
93d7153aa172665f55b04463b831ad556269c3efbrianp<directivesynopsis>
bc6600a6207e5d15b895294e370e4e3320a803d8stoddard<description>Provide a hook for the type_checker phase of request processing</description>
bc6600a6207e5d15b895294e370e4e3320a803d8stoddard<syntax>LuaHookTypeChecker /path/to/lua/script.lua hook_function_name</syntax>
bc6600a6207e5d15b895294e370e4e3320a803d8stoddard<contextlist><context>server config</context><context>virtual host</context>
bc6600a6207e5d15b895294e370e4e3320a803d8stoddard<context>directory</context><context>.htaccess</context>
bc6600a6207e5d15b895294e370e4e3320a803d8stoddard</contextlist>
4e21f1a207aefa9796dc758bf7274b0f1fea780fstoddard This directive provides a hook for the type_checker phase of the request processing.
7a23067e782dd5612d4d4b539906e1733b664df7jwoolley This phase is where requests are assigned a content type and a handler, and thus can
5c214a63f9722864ac4983995da11353779515dbrederpj be used to modify the type and handler based on input:
5c214a63f9722864ac4983995da11353779515dbrederpj LuaHookTypeChecker /path/to/lua/script.lua type_checker
9f20717d827f2113a23dfa45539813171cf626eaianh </highlight>
9f20717d827f2113a23dfa45539813171cf626eaianh function type_checker(r)
9f20717d827f2113a23dfa45539813171cf626eaianh if r.uri:match("%.to_gif$") then -- match foo.png.to_gif
a0db2f093595083300ad3438314f90921405ccf9wrowe r.content_type = "image/gif" -- assign it the image/gif type
a0db2f093595083300ad3438314f90921405ccf9wrowe r.handler = "gifWizard" -- tell the gifWizard module to handle this
a0db2f093595083300ad3438314f90921405ccf9wrowe r.filename = r.uri:gsub("%.to_gif$", "") -- fix the filename requested
fb59f85aab19883025f619727948b8088232cc4brederpj </highlight>
1a1cf0ee9229ee29e5750b25dd94dbb9b04072cfianh</directivesynopsis>
1a1cf0ee9229ee29e5750b25dd94dbb9b04072cfianh<directivesynopsis>
0bbb249eafe9ef9508821f0ef58e7440625ecd62trawick<description>Provide a hook for the auth_checker phase of request processing</description>
0bbb249eafe9ef9508821f0ef58e7440625ecd62trawick<syntax>LuaHookAuthChecker /path/to/lua/script.lua hook_function_name [early|late]</syntax>
61afed048a4d67ed923d52e5c865c0f10a8e9e73trawick<contextlist><context>server config</context><context>virtual host</context>
7a23067e782dd5612d4d4b539906e1733b664df7jwoolley<context>directory</context><context>.htaccess</context>
7a23067e782dd5612d4d4b539906e1733b664df7jwoolley</contextlist>
7a23067e782dd5612d4d4b539906e1733b664df7jwoolley<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
6032a7c97a25c52f4bdd78ce23f2010e52c9e81arederpj<p>Invoke a lua function in the auth_checker phase of processing
6032a7c97a25c52f4bdd78ce23f2010e52c9e81arederpja request. This can be used to implement arbitrary authentication
ba2e14e474516f1c75a96b4f6d1a9dec332175efianhand authorization checking. A very simple example:
f0791c5bdfd36969d292a4092df076aa6d1c34ccwrowerequire 'apache2'
f0791c5bdfd36969d292a4092df076aa6d1c34ccwrowe-- fake authcheck hook
f0791c5bdfd36969d292a4092df076aa6d1c34ccwrowe-- If request has no auth info, set the response header and
749011213737e8d0cd6ca78d5eb532ec6f6b9fdfianh-- return a 401 to ask the browser for basic auth info.
749011213737e8d0cd6ca78d5eb532ec6f6b9fdfianh-- If request has auth info, don't actually look at it, just
749011213737e8d0cd6ca78d5eb532ec6f6b9fdfianh-- pretend we got userid 'foo' and validated it.
ec69fc6e323eb1f3112966e06e9e37be608d052cianh-- Then check if the userid is 'foo' and accept the request.
ec69fc6e323eb1f3112966e06e9e37be608d052cianhfunction authcheck_hook(r)
e7bf4d6f15d04e86e20002e65f60d7fbf80e5974stoddard -- look for auth info
8ab933f1df663f95c27e2ce5772127d4f3a10e0bstriker auth = r.headers_in['Authorization']
de42d3dfd83a4cc62f0dd6b79ee5cbcfa69fd503brianp if auth ~= nil then
de42d3dfd83a4cc62f0dd6b79ee5cbcfa69fd503brianp -- fake the user
44380fc1701cbb8b0a977d5a1497f0c6ee912e0bfielding if r.user == nil then
44380fc1701cbb8b0a977d5a1497f0c6ee912e0bfielding r:debug("authcheck: user is nil, returning 401")
44380fc1701cbb8b0a977d5a1497f0c6ee912e0bfielding r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
44380fc1701cbb8b0a977d5a1497f0c6ee912e0bfielding elseif r.user == "foo" then
44380fc1701cbb8b0a977d5a1497f0c6ee912e0bfielding r:debug('user foo: OK')
a8dda281113c5038945423320d8c9b42e3d1ddb1jwoolley r:debug("authcheck: user='" .. r.user .. "'")
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp r.err_headers_out['WWW-Authenticate'] = 'Basic realm="WallyWorld"'
a06237883ed0c6e8600dbb1ef71b8a67963192aamjc return 401
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe</highlight>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe <note><title>Ordering</title><p>The optional arguments "early" or "late"
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe control when this script runs relative to other modules.</p></note>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe</directivesynopsis>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe<directivesynopsis>
a06237883ed0c6e8600dbb1ef71b8a67963192aamjc<description>Provide a hook for the access_checker phase of request processing</description>
a06237883ed0c6e8600dbb1ef71b8a67963192aamjc<syntax>LuaHookAccessChecker /path/to/lua/script.lua hook_function_name [early|late]</syntax>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe<contextlist><context>server config</context><context>virtual host</context>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe<context>directory</context><context>.htaccess</context>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe</contextlist>
a06237883ed0c6e8600dbb1ef71b8a67963192aamjc<compatibility>The optional third argument is supported in 2.3.15 and later</compatibility>
a06237883ed0c6e8600dbb1ef71b8a67963192aamjc<p>Add your hook to the access_checker phase. An access checker
a06237883ed0c6e8600dbb1ef71b8a67963192aamjchook function usually returns OK, DECLINED, or HTTP_FORBIDDEN.</p>
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe <note><title>Ordering</title><p>The optional arguments "early" or "late"
39dde7f4cd79d701cc14e5beac8ea528bc58d038wrowe control when this script runs relative to other modules.</p></note>
a06237883ed0c6e8600dbb1ef71b8a67963192aamjc</directivesynopsis>
268ac122b1fd6fa948b30bdf0d8c0d80e75d68dawrowe<directivesynopsis>
268ac122b1fd6fa948b30bdf0d8c0d80e75d68dawrowe<description>Provide a hook for the insert_filter phase of request processing</description>
268ac122b1fd6fa948b30bdf0d8c0d80e75d68dawrowe<syntax>LuaHookInsertFilter /path/to/lua/script.lua hook_function_name</syntax>
268ac122b1fd6fa948b30bdf0d8c0d80e75d68dawrowe<contextlist><context>server config</context><context>virtual host</context>
268ac122b1fd6fa948b30bdf0d8c0d80e75d68dawrowe<context>directory</context><context>.htaccess</context>
6ba861fd6c705eaeb1f9bb97df86ddea6895e263minfrin</contextlist>
268ac122b1fd6fa948b30bdf0d8c0d80e75d68dawrowe</directivesynopsis>
b78ed256f4b99e72836d36fd68d4e7a26dbe032cianh<directivesynopsis>
698670444b30b79e808155739f98c39bec35f72awrowe<description>Controls how parent configuration sections are merged into children</description>
e7ec1c54206901c9369e40f471b71836c78e017dwrowe<syntax>LuaInherit none|parent-first|parent-last</syntax>
57bea0f0559e31536af3b7b5859d3681ee29a34cwrowe<contextlist><context>server config</context><context>virtual host</context>
57bea0f0559e31536af3b7b5859d3681ee29a34cwrowe<context>directory</context><context>.htaccess</context>
57bea0f0559e31536af3b7b5859d3681ee29a34cwrowe</contextlist>
57bea0f0559e31536af3b7b5859d3681ee29a34cwrowe <usage><p>By default, if LuaHook* directives are used in overlapping
94e2b2d12fa269af16fa63a6270d3336d9f126f2trawick Directory or Location configuration sections, the scripts defined in the
94e2b2d12fa269af16fa63a6270d3336d9f126f2trawick more specific section are run <em>after</em> those defined in the more
94e2b2d12fa269af16fa63a6270d3336d9f126f2trawick generic section (LuaInherit parent-first). You can reverse this order, or
94e2b2d12fa269af16fa63a6270d3336d9f126f2trawick make the parent context not apply at all.</p>
35313c8d7368125c3e95d3118238d2be9a613000trawick <p> In previous 2.3.x releases, the default was effectively to ignore LuaHook*
35313c8d7368125c3e95d3118238d2be9a613000trawick directives from parent configuration sections.</p></usage>
55da18d54a0ba74dc51aecba5b0daf71a2ed10a7trawick</directivesynopsis>
55da18d54a0ba74dc51aecba5b0daf71a2ed10a7trawick<directivesynopsis>
55da18d54a0ba74dc51aecba5b0daf71a2ed10a7trawick<description>Provide a hook for the quick handler of request processing</description>
c51f2b89da23e3371959a74808dee1792d96f5c1wsanchez<syntax>LuaQuickHandler /path/to/script.lua hook_function_name</syntax>
c51f2b89da23e3371959a74808dee1792d96f5c1wsanchez<contextlist><context>server config</context><context>virtual host</context>
c51f2b89da23e3371959a74808dee1792d96f5c1wsanchez</contextlist>
79c9b0ac498d97336874edba0daf9f544ad14671trawick <note><title>Context</title><p>This directive is not valid in <directive
79c9b0ac498d97336874edba0daf9f544ad14671trawick type="section" module="core">Directory</directive>, <directive
79c9b0ac498d97336874edba0daf9f544ad14671trawick type="section" module="core">Files</directive>, or htaccess
5a7d934619b2be92e18be5dd3366f4ac6ddeab43trawick</directivesynopsis>
5a7d934619b2be92e18be5dd3366f4ac6ddeab43trawick<directivesynopsis>
5a70e5b66eb7758d0e64e070211f699fc83fca70wrowe<description>Plug an authorization provider function into <module>mod_authz_core</module>
5a70e5b66eb7758d0e64e070211f699fc83fca70wrowe</description>
5a70e5b66eb7758d0e64e070211f699fc83fca70wrowe<syntax>LuaAuthzProvider provider_name /path/to/lua/script.lua function_name</syntax>
5a70e5b66eb7758d0e64e070211f699fc83fca70wrowe<contextlist><context>server config</context> </contextlist>
1d3fbd2d9f03c0826977d940a2081401edf522d4jerenkrantz<p>After a lua function has been registered as authorization provider, it can be used
b5cc0253789825ace46944dc9cde744be08dd77fjerenkrantzwith the <directive module="mod_authz_core">Require</directive> directive:</p>
e4bb84f3c11f282d3ba66f64940b1b8e13f85e7asliveLuaAuthzProvider foo authz.lua authz_check_foo
e4bb84f3c11f282d3ba66f64940b1b8e13f85e7aslive<Location />
e4bb84f3c11f282d3ba66f64940b1b8e13f85e7aslive Require foo johndoe
e4bb84f3c11f282d3ba66f64940b1b8e13f85e7aslive</Location>
e4bb84f3c11f282d3ba66f64940b1b8e13f85e7aslive</highlight>
ba2bab42e97405dc41c0f8fe3416f7f9a79ed7a9brianprequire "apache2"
ba2bab42e97405dc41c0f8fe3416f7f9a79ed7a9brianpfunction authz_check_foo(r, who)
756b54396a86db555817bb52149d91b60d00e35fwrowe</highlight>
24efed0910118b762a4eb84830875d4714b8d315ianh</directivesynopsis>
50e60f30bdc074fbc887f0b98f4d570457ac97c9brianp</modulesynopsis>