<li><img alt="" src="../images/down.gif" /> <a href="#basic_remap">Example 1: A basic remapping module</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#mass_vhost">Example 2: Mass virtual hosting</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#basic_auth">Example 3: A basic authorization hook</a></li>
-<li><img alt="" src="../images/down.gif" /> <a href="#map_handler">Example 4: Authorization using LuaAuthzProvider</a></li>
+<li><img alt="" src="../images/down.gif" /> <a href="#authz">Example 4: Authorization using LuaAuthzProvider</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#map_handler">Example 5: Overlays using LuaMapHandler</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#mod_status_lua">Example 6: Basic Lua scripts</a></li>
<li><img alt="" src="../images/down.gif" /> <a href="#String_manipulation">HTTPd bindings: String manipulation</a></li>
-- Function for querying the database for saved vhost entries
function query_vhosts(host)
if not cached_vhosts[host] or (cached_vhosts[host] and cached_vhosts[host].updated < os.time() - timeout) then
- local db = apache2.dbopen("mod_dbd")
+ local db = apache2.dbopen(r,"mod_dbd")
local _host = db:escape(_host)
local res, err = db:query( ("SELECT `destination` FROM `vhosts` WHERE `hostname` = '%s' LIMIT 1"):format(_host) )
if res and #res == 1 then
-- Function for querying the database for the account's password (stored as a salted SHA-1 hash)
function fetch_password(user)
if not accounts[user] or (accounts[user] and accounts[user].updated < os.time() - timeout) then
- local db = apache2.dbopen("mod_dbd")
+ local db = apache2.dbopen(r, "mod_dbd")
local usr = db:escape(user)
local res, err = db:query( ("SELECT `password` FROM `accounts` WHERE `user` = '%s' LIMIT 1"):format(usr) )
if res and #res == 1 then
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
-<h2><a name="map_handler" id="map_handler">Example 4: Authorization using LuaAuthzProvider</a></h2>
+<h2><a name="authz" id="authz">Example 4: Authorization using LuaAuthzProvider</a></h2>
<pre class="prettyprint lang-config">
LuaAuthzProvider rights /path/to/lua/script.lua rights_handler
<div class="section">
<h2><a name="String_manipulation" id="String_manipulation">HTTPd bindings: String manipulation</a></h2>
+<p>
<a href="#apache2.base64_encode">apache2.base64_encode</a>
<br />
<a href="#apache2.base64_decode">apache2.base64_decode</a>
<br />
<a href="#apache2.escape_logitem">apache2.escape_logitem</a>
<br />
+</p>
<h3><a name="apache2.base64_decode" id="apache2.base64_decode">apache2.base64_decode(
request_rec<em> r</em>, string<em> string</em>
)
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The string to decode</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local str = "This is a test"
local encoded = apache2.base64_encode(str)
local decoded = apache2.base64_decode(encoded)
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.base64_encode" id="apache2.base64_encode">apache2.base64_encode(
request_rec<em> r</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The string to encode</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local str = "This is a test"
local encoded = apache2.base64_encode(str)
local decoded = apache2.base64_decode(encoded)
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.escape" id="apache2.escape">apache2.escape(
request_rec<em> r</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The string to escape</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local str = "This is a test"
local escaped = apache2.escape(str)
print(escaped) -- prints "This+is+a+test"
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.escape_logitem" id="apache2.escape_logitem">apache2.escape_logitem(
request_rec<em> r</em>, string<em> path</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The string to escape</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The converted string
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.escapehtml" id="apache2.escapehtml">apache2.escapehtml(
request_rec<em> r</em>, string<em> html</em>, boolean<em> toasc</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>Whether to escape all non-ASCI characters as &#nnn;</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local html = "<b>Testing!</b>"
local escaped = apache2.escapehtml(html)
r:puts(escaped) -- prints "&lt;b&gt;Testing!&lt;/b&gt;"
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.md5" id="apache2.md5">apache2.md5(
request_rec<em> r</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The (binary) string to digest</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local text = "The quick brown fox jumps over the lazy dog"
local md5 = apache2.md51(text)
r:puts(md5) -- prints out "9e107d9d372bb6826bd81d3542a419d6"
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.os_escape_path" id="apache2.os_escape_path">apache2.os_escape_path(
request_rec<em> r</em>, string<em> path</em>, boolean<em> partial</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>partial if set, assume that the path will be appended to something with a '/' in it (and thus does not prefix "./")</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local path = ap_os_escape_path("C:/foo/bar.txt")
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.sha1" id="apache2.sha1">apache2.sha1(
request_rec<em> r</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The (binary) string to digest</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local text = "The quick brown fox jumps over the lazy dog"
local sha1 = apache2.sha1(text)
r:puts(sha1) -- prints out "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.unescape" id="apache2.unescape">apache2.unescape(
request_rec<em> r</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The string to unescape</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local str = "This+is+a+test"
local unescaped = apache2.unescape(str)
print(unescaped) -- prints "This is a test"
</pre>
-</p>
-<br />
-<br />
+<p> </p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="Request_handling" id="Request_handling">HTTPd bindings: Request handling</a></h2>
+<p>
<a href="#apache2.sendfile">apache2.sendfile</a>
<br />
<a href="#apache2.port">apache2.port</a>
<br />
<a href="#apache2.satisfies">apache2.satisfies</a>
<br />
+</p>
<h3><a name="apache2.add_input_filter" id="apache2.add_input_filter">apache2.add_input_filter(
request_rec<em> r</em>, string<em> filter</em>
)
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The name of the filter handler to add</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
apache2.add_input_filter(r, "SPAM_FILTER") -- Check input for spam..?
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.add_output_filter" id="apache2.add_output_filter">apache2.add_output_filter(
request_rec<em> r</em>, string<em> filter</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The name of the filter handler to add</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
apache2.add_input_filter(r, "INCLUDES") -- Turn out output into an SSI-enabled document.
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.allowoverrides" id="apache2.allowoverrides">apache2.allowoverrides(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local ctx = apache2.allowoverrides(r)
if ctx:match("AuthCfg") then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.auth_name" id="apache2.auth_name">apache2.auth_name(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The current authorization realm
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.auth_type" id="apache2.auth_type">apache2.auth_type(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The current Authorization type used in the request
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.context_document_root" id="apache2.context_document_root">apache2.context_document_root(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.context_prefix" id="apache2.context_prefix">apache2.context_prefix(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.flush" id="apache2.flush">apache2.flush(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
r:puts("This is buffered")
apache2.flush(r) -- now it's written to the client.
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.get_basic_auth_pw" id="apache2.get_basic_auth_pw">apache2.get_basic_auth_pw(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The password from a basic authorization request or nil if none was supplied
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.get_limit_req_body" id="apache2.get_limit_req_body">apache2.get_limit_req_body(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local limit = apache2.get_limit_req_body(r)
r:puts("You can't upload files bigger than ", limit, " bytes!")
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.get_server_name" id="apache2.get_server_name">apache2.get_server_name(
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local name = apache2.get_server_name(r)
r:puts("The ServerName is set to: ", name)
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.getenv" id="apache2.getenv">apache2.getenv(
request_rec<em> r</em>, string<em> key</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>key</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local env = apache2.getenv("HTTP_HOST")
if env and env:len() > 0 then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.make_etag" id="apache2.make_etag">apache2.make_etag(
request_rec<em> r</em>, boolean<em> force_weak</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>force_weak Force the entity tag to be weak - it could be modified again in as short an interval.</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The entity tag
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.options" id="apache2.options">apache2.options(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local ctx = apache2.options(r)
if ctx:match("MultiViews") then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.port" id="apache2.port">apache2.port(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local port = apache2.port(r)
r:puts("We are listening on port ", port)
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.request_has_body" id="apache2.request_has_body">apache2.request_has_body(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if apache2.request_has_body(r) then
-- do stuff with the req body
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.requestbody" id="apache2.requestbody">apache2.requestbody(
request_rec<em> r</em>, string<em> filename</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>filename</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if tonumber(r.headers_in['Content-Length'] or 0) < 10000 then
local smallfile = apache2.requestbody(r) -- fetch a small file into memory
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.satisfies" id="apache2.satisfies">apache2.satisfies(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local how = apache2.satisfies(r)
if how == "SATISFY_ANY" then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.send_interim_response" id="apache2.send_interim_response">apache2.send_interim_response(
request_rec<em> r</em>, boolean<em> send_headers</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>send_headers Whether to send&clear headers in r->headers_out</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
apache2.send_interim_response(r, false)
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.sendfile" id="apache2.sendfile">apache2.sendfile(
request_rec<em> r</em>, string<em> filename</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The file to send</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
apache2.sendfile(r, "/foo/bar/test.png") -- sends /foo/bar/test.png via sendfile
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.set_context_prefix" id="apache2.set_context_prefix">apache2.set_context_prefix(
request_rec<em> r</em>, string<em> prefix</em>, string<em> document</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The corresponding directory on disk, without trailing slash</td>
</tr>
</table>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.set_document_root" id="apache2.set_document_root">apache2.set_document_root(
request_rec<em> r</em>, string<em> root</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>root</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
-- Suppose our real document root is /var/bar, then...
if r.hostname == "www.foo.com" then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.set_keepalive" id="apache2.set_keepalive">apache2.set_keepalive(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
True if keepalive can be set, false otherwise
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.setenv" id="apache2.setenv">apache2.setenv(
request_rec<em> r</em>, string<em> key</em>, string<em> val</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>val</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
apache2.setenv("FOO_VAL", "bar and stuff")
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.some_auth_required" id="apache2.some_auth_required">apache2.some_auth_required(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if apache2.some_auth_required(r) then
print("debug: auth is required for this request\n")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="Parser_functions" id="Parser_functions">HTTPd bindings: Parser functions</a></h2>
+<p>
<a href="#apache2.expr">apache2.expr</a>
<br />
<a href="#apache2.regex">apache2.regex</a>
<br />
<a href="#apache2.strcmp_match">apache2.strcmp_match</a>
<br />
+</p>
<h3><a name="apache2.expr" id="apache2.expr">apache2.expr(
request_rec<em> r</em>, string<em> expression</em>
)
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>expression</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if apache2.expr("%{REQUEST_URI} =~ /force-gzip") then
apache2.add_output_filter(r, "DEFLATE")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.regex" id="apache2.regex">apache2.regex(
request_rec<em> r</em>, string<em> expression</em>, string<em> source</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>the source string to capture from</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local matches = apache2.regex(r, [[(\S+) kitty]], "Hello kitty")
if matches and matches[1] then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.strcmp_match" id="apache2.strcmp_match">apache2.strcmp_match(
string<em> str</em>, string<em> expexted</em>, boolean<em> ignoreCase</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>Whether to ignore case when matching</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if apache2.strcmp_match("foo.bar", "foo.*") then
r:puts("It matches!")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="Server_settings" id="Server_settings">HTTPd bindings: Server settings</a></h2>
+<p>
<a href="#apache2.add_version_component">apache2.add_version_component</a>
<br />
<a href="#apache2.banner">apache2.banner</a>
<br />
<a href="#apache2.exists_config_define">apache2.exists_config_define</a>
<br />
+</p>
<h3><a name="apache2.add_version_component" id="apache2.add_version_component">apache2.add_version_component(
request_rec<em> r</em>, string<em> component</em>
)
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The component to add</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if not apache2.banner():match("FooModule") then -- Make sure we haven't added it already
apache2.add_version_component(r, "FooModule/1.0")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.banner" id="apache2.banner">apache2.banner(
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br />
The server banner
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.custom_response" id="apache2.custom_response">apache2.custom_response(
request_rec<em> r</em>, number<em> status</em>, string<em> string</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The custom response. This can be a static string, a file or a URL</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
apache2.custom_response(r, 404, "Not found!!")
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.exists_config_define" id="apache2.exists_config_define">apache2.exists_config_define(
string<em> name</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The define to check for</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
if apache2.exists_config_define("FOO") then
r:puts("This server was started with -DFOO")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.get_server_built" id="apache2.get_server_built">apache2.get_server_built(
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br />
The date the server was built
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.is_initial_req" id="apache2.is_initial_req">apache2.is_initial_req(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
True if this is the main request, false if it is a sub-request
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.loaded_modules" id="apache2.loaded_modules">apache2.loaded_modules(
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br />
A table containing the name (c filename) of all loaded modules
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.module_info" id="apache2.module_info">apache2.module_info(
string<em> c</em>, string<em> file</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>file</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The various commands available to this module as a table, or nil if the module wasn't found.
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.mpm_query" id="apache2.mpm_query">apache2.mpm_query(
number<em> i</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>i</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The queried value
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.runtime_dir_relative" id="apache2.runtime_dir_relative">apache2.runtime_dir_relative(
request_rec<em> r</em>, string<em> file</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>file</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The path of a file relative to the default runtime directory
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.scoreboard_process" id="apache2.scoreboard_process">apache2.scoreboard_process(
request_rec<em> r</em>, number<em> child</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The server child to query</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The scoreboard for a server daemon as a table
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.scoreboard_worker" id="apache2.scoreboard_worker">apache2.scoreboard_worker(
request_rec<em> r</em>, number<em> child</em>, number<em> thread</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The thread to query</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The scoreboard for a single thread as a table
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.server_info" id="apache2.server_info">apache2.server_info(
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br />
A table with information about the server program
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.started" id="apache2.started">apache2.started(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
The time when the server was (re)started
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.state_query" id="apache2.state_query">apache2.state_query(
number<em> field</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>Which information is requested</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local gen = apache2.state_query(2)
r:puts("This is generation no. " .. gen .. " of the top-level parent")
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.terminate" id="apache2.terminate">apache2.terminate(
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
-<br />
-<br />
+<p>None</p>
+<p> </p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="Database_connectivity" id="Database_connectivity">HTTPd bindings: Database connectivity</a></h2>
+<p>
<a href="#apache2.dbopen">apache2.dbopen</a>
<br />
<a href="#db:query">db:query</a>
<br />
<a href="#db:close">db:close</a>
<br />
+</p>
<h3><a name="apache2.dbopen" id="apache2.dbopen">apache2.dbopen(
request_rec<em> r</em>, string<em> dbtype</em>, string<em> conn_string</em>
)
</a></h3>
<p>
-Opens up a new database connection. See the DB functions for mod_pLua for more info on this.
+Opens up a new database connection.
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>connection string</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local db, error = apache2.dbopen(r, "mod_dbd")
if error then
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="db:close" id="db:close">db:close(
request_rec<em> r</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The mod_lua request handle</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local db = apache2.dbopen(r, "mod_dbd") -- open a db connection
db:close() -- close it down
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="db:do" id="db:do">db:do(
request_rec<em> r</em>, string<em> query</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The SQL statement to execute</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local db = apache2.dbopen(r, "mod_dbd")
local affected = db:do("DELETE FROM `table` WHERE 1")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
<h3><a name="db:query" id="db:query">db:query(
request_rec<em> r</em>, string<em> query</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The SQL statement to execute</td>
</tr>
</table>
-</p>
<p>
<em>Return value(s):</em>
<br />
</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
local db = apache2.dbopen(r, "mod_dbd")
local result, error = db:query("SELECT * FROM `table` WHERE 1")
end
</pre>
-</p>
-<br />
-<br />
+<p> </p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="Miscellaneous" id="Miscellaneous">HTTPd bindings: Miscellaneous</a></h2>
+<p>
<a href="#apache2.clock">apache2.clock</a>
<br />
<a href="#apache2.sleep">apache2.sleep</a>
<br />
+</p>
<h3><a name="apache2.clock" id="apache2.clock">apache2.clock(
)
</p>
<p>
<em>Arguments:</em>
-<br />
- None<br />
</p>
+<p>None</p>
<p>
<em>Return value(s):</em>
<br />
The current time in microseconds.
</p>
-<br />
-<br />
+<p> </p>
<h3><a name="apache2.sleep" id="apache2.sleep">apache2.sleep(
number<em> seconds</em>
</p>
<p>
<em>Arguments:</em>
-<br />
+</p>
<table class="bordered">
<tr>
<th>Argument</th>
<td>The number of seconds to sleep.</td>
</tr>
</table>
-</p>
<p>
<em>Example:</em>
-<br />
+</p>
<pre class="prettyprint lang-lua">
r:puts("this is ")
apache2.flush(r)
r:puts("delayed")
</pre>
-</p>
-<br />
-<br />
+<p> </p>
</div></div>
<div class="bottomlang">