You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2012/09/06 12:32:32 UTC

svn commit: r1381550 - /httpd/httpd/trunk/docs/manual/developer/lua.html.en

Author: humbedooh
Date: Thu Sep  6 10:32:31 2012
New Revision: 1381550

URL: http://svn.apache.org/viewvc?rev=1381550&view=rev
Log:
xforms

Modified:
    httpd/httpd/trunk/docs/manual/developer/lua.html.en

Modified: httpd/httpd/trunk/docs/manual/developer/lua.html.en
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/developer/lua.html.en?rev=1381550&r1=1381549&r2=1381550&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/developer/lua.html.en (original)
+++ httpd/httpd/trunk/docs/manual/developer/lua.html.en Thu Sep  6 10:32:31 2012
@@ -162,7 +162,11 @@ end
 <div class="section">
 <h2><a name="basic_remap" id="basic_remap">Example 1: A basic remapping module</a></h2>
 <p>
-
+    These first examples show how mod_lua can be used to rewrite URIs in the same 
+    way that one could do using <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> or 
+    <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>, but with more clarity 
+    on how the decision-making takes place, as well as allowing for more complex 
+    decisions than would otherwise be allowed with said directives.
 </p>
 
 <pre class="prettyprint lang-config">
@@ -181,7 +185,7 @@ LuaHookTranslateName /path/too/foo.lua r
 
 function remap(r)
     -- Test if the URI matches our criteria
-    local barFile =  r.uri:match("/foo/([a-zA-Z0-9]+%.bar)")
+    local barFile =  r.uri:match("/foo/([a-zA-Z0-9]+)%.bar")
     if barFile then
         r.filename = "/internal/" .. barFile
     end
@@ -198,7 +202,12 @@ end
     Advanced remap example.
     This example will evaluate some conditions, and based on that, 
     remap a file to one of two destinations, using a rewrite map.
-    
+    This is similar to mixing AliasMatch and ProxyPass, but 
+    without them clashing in any way. Assuming we are on example.com, then:
+
+    http://example.com/photos/test.png will be rewritten as /uploads/www/test.png
+    http://example.com/ext/foo.html will be proxied to http://www.external.com/foo.html
+    URIs that do not match, will be served by their respective default handlers
 ]]--
 
 local map = {
@@ -209,7 +218,7 @@ local map = {
                 },
       externals = {
                    source = [[^/ext/(.*)$]],
-                   destination = [[http://www.example.com/$1]],
+                   destination = [[http://www.external.com/$1]],
                    proxy = true
                 }
 }
@@ -247,7 +256,12 @@ bla bla
 <div class="section">
 <h2><a name="mass_vhost" id="mass_vhost">Example 2: Mass virtual hosting</a></h2>
 <p>
-
+    As with simple and advanced rewriting, you can use mod_lua for dynamically 
+    assigning a hostname to a specific document root, much like 
+    <code class="module"><a href="../mod/mod_vhost_alias.html">mod_vhost_alias</a></code> does, but with more control over what goes 
+    where. This could be as simple as a table holding the information about which 
+    host goes into which folder, or more advanced, using a database holding the 
+    document roots of each hostname.
 </p>
 
 <pre class="prettyprint lang-config">
@@ -302,15 +316,16 @@ local cached_vhosts = {}
 local timeout = 60
 
 -- Function for querying the database for saved vhost entries
-function query_vhosts(host)
+function query_vhosts(r)
+    local host = r.hostname
     if not cached_vhosts[host] or (cached_vhosts[host] and cached_vhosts[host].updated &lt; os.time() - timeout) then
-        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) )
+        local db,err = ap.dbopen(r,"mod_dbd")
+        local _host = db:escape(r,host)
+        local res, err = db:query(r, ("SELECT `destination` FROM `vhosts` WHERE `hostname` = '%s' LIMIT 1"):format(_host) )
         if res and #res == 1 then
             cached_vhosts[host] = { updated = os.time(), destination = res[1][1] }
         else
-            cached_vhosts[host] = nil
+            cached_vhosts[host] = { updated = os.time(), destination = nil } -- don't re-query whenever there's no result, wait a while.
         end
         db:close()
     end
@@ -323,12 +338,12 @@ end
         
 function mass_vhost(r)
     -- Check whether the hostname is in our database
-    local destination = query_vhosts(r.hostname)
+    local destination = query_vhosts(r)
     if destination then
         -- If found, rewrite and change document root
         local filename = r.filename:sub(r.document_root:len()+1)
         r.filename = destination .. filename
-        apahce2.set_document_root(destination)
+        ap.set_document_root(r,destination)
         return apache2.OK
     end
     return apache2.DECLINED
@@ -338,12 +353,16 @@ end
 
 
 <p>
-bla bla
+
 </p>
 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 <div class="section">
 <h2><a name="basic_auth" id="basic_auth">Example 3: A basic authorization hook</a></h2>
-
+<p>
+    With the authorization hooks, you can add custom auth phases to your request 
+    processing, allowing you to either add new requirements that were not previously 
+    supported by httpd, or tweaking existing ones to accommodate your needs. 
+</p>
 <pre class="prettyprint lang-config">
 LuaHookAuthChecker /path/too/foo.lua check_auth
 </pre>
@@ -459,7 +478,12 @@ end
 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 <div class="section">
 <h2><a name="authz" id="authz">Example 4: Authorization using LuaAuthzProvider</a></h2>
-
+<p>
+    If you require even more advanced control over your authorization phases, 
+    you can add custom authz providers to help you manage your server. The 
+    example below shows you how you can split a single htpasswd file into 
+    groups with different permissions:
+</p>
 <pre class="prettyprint lang-config">
 LuaAuthzProvider rights /path/to/lua/script.lua rights_handler
 &lt;Directory /www/private&gt;
@@ -505,7 +529,9 @@ end
 </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 5: Overlays using LuaMapHandler</a></h2>
-
+<p>
+Coming soon!
+</p>
 <pre class="prettyprint lang-config">
 LuaMapHandler ^/portal/([a-z]+)/   /path/to/lua/script.lua handle_$1
 </pre>
@@ -513,6 +539,9 @@ LuaMapHandler ^/portal/([a-z]+)/   /path
 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 <div class="section">
 <h2><a name="mod_status_lua" id="mod_status_lua">Example 6: Basic Lua scripts</a></h2>
+<p>
+Also coming soon
+</p>
 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
 <div class="section">
 <h2><a name="String_manipulation" id="String_manipulation">HTTPd bindings: String manipulation</a></h2>
@@ -779,7 +808,7 @@ r:puts(md5) -- prints out "9e107d9d372bb
     </a></h3>
 
 <p>
-convert an OS path to a URL in an OS dependant way.
+convert an OS path to a URL in an OS dependent way.
         </p>
 <p>
 <em>Arguments:</em>