From: Daniel Gruno <humbedooh@apache.org> Date: Sun, 5 May 2013 08:07:11 +0000 (+0000) Subject: xforms X-Git-Tag: 2.5.0-alpha~5501 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e50cc40704eef4739a0e814d1600c6218f8ff97;p=apache xforms git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1479254 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/developer/lua.html.en b/docs/manual/developer/lua.html.en index 4a459650db..efe3a61dfc 100644 --- a/docs/manual/developer/lua.html.en +++ b/docs/manual/developer/lua.html.en @@ -33,14 +33,9 @@ <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="#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="#loadbalancing">Example 5: A rudimentary load balancer</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#map_handler">Example 6: 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> -<li><img alt="" src="../images/down.gif" /> <a href="#Request_handling">HTTPd bindings: Request handling</a></li> -<li><img alt="" src="../images/down.gif" /> <a href="#Parser_functions">HTTPd bindings: Parser functions</a></li> -<li><img alt="" src="../images/down.gif" /> <a href="#Server_settings">HTTPd bindings: Server settings</a></li> -<li><img alt="" src="../images/down.gif" /> <a href="#Database_connectivity">HTTPd bindings: Database connectivity</a></li> -<li><img alt="" src="../images/down.gif" /> <a href="#Miscellaneous">HTTPd bindings: Miscellaneous</a></li> </ul><h3>See also</h3><ul class="seealso"><li><a href="../mod/mod_lua.html">mod_lua</a></li><li><a href="modguide.html">Developing modules for Apache 2.4</a></li><li><a href="request.html">Request Processing in Apache 2.4</a></li><li><a href="hooks.html">Apache 2.x Hook Functions</a></li></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> <div class="section"> @@ -528,1492 +523,75 @@ 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> +<h2><a name="loadbalancing" id="loadbalancing">Example 5: A rudimentary load balancer</a></h2> <p> -Coming soon! + This is an example of how you can create a load balancing mechanism. + In this example, we will be setting/getting the number of requests served + by each backend using IVM variables, and preferring the backend with least + requests served in total: </p> <pre class="prettyprint lang-config"> -LuaMapHandler ^/portal/([a-z]+)/ /path/to/lua/script.lua handle_$1 +LuaHookTranslateName /path/to/script.lua proxy_handler </pre> -</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> - -<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">apache2.escape</a> -<br /> -<a href="#apache2.unescape">apache2.unescape</a> -<br /> -<a href="#apache2.escapehtml">apache2.escapehtml</a> -<br /> -<a href="#apache2.md5">apache2.md5</a> -<br /> -<a href="#apache2.sha1">apache2.sha1</a> -<br /> -<a href="#apache2.os_escape_path">apache2.os_escape_path</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> - ) - </a></h3> - -<p> -Decodes a base64-encoded string - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>string</td> -<td>The string to decode</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The base64-decoded string. - </p> -<p> -<em>Example:</em> -</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> </p> - -<h3><a name="apache2.base64_encode" id="apache2.base64_encode">apache2.base64_encode( - request_rec<em> r</em>, string<em> string</em> - ) - </a></h3> - -<p> -Encodes a string using the base64 encoding scheme. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>string</td> -<td>The string to encode</td> -</tr> -</table> -<p> -<em>Example:</em> -</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> </p> - -<h3><a name="apache2.escape" id="apache2.escape">apache2.escape( - request_rec<em> r</em>, string<em> string</em> - ) - </a></h3> - -<p> -url-escapes a string - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>string</td> -<td>The string to escape</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The URL-escaped string. - </p> -<p> -<em>Example:</em> -</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> </p> - -<h3><a name="apache2.escape_logitem" id="apache2.escape_logitem">apache2.escape_logitem( - request_rec<em> r</em>, string<em> path</em> - ) - </a></h3> - -<p> -Escape a string for logging - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>path</td> -<td>The string to escape</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The converted string - </p> -<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> - ) - </a></h3> - -<p> -Escapes HTML entities. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>html</td> -<td>The HTML code to escape</td> -</tr> -<tr> -<td>toasc</td> -<td>Whether to escape all non-ASCI characters as &#nnn;</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The escaped HTML code. - </p> -<p> -<em>Example:</em> -</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> </p> - -<h3><a name="apache2.md5" id="apache2.md5">apache2.md5( - request_rec<em> r</em>, string<em> string</em> - ) - </a></h3> - -<p> -Computes an MD5 digest sum based on a string (binary safe) - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>string</td> -<td>The (binary) string to digest</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The MD5 digest sum of the data provided - </p> -<p> -<em>Example:</em> -</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> </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> - ) - </a></h3> - -<p> -convert an OS path to a URL in an OS dependent way. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>path</td> -<td>The path to convert</td> -</tr> -<tr> -<td>partial</td> -<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> -<em>Return value(s):</em> -<br /> -The converted URL - </p> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -local path = ap_os_escape_path("C:/foo/bar.txt") - </pre> - -<p> </p> - -<h3><a name="apache2.sha1" id="apache2.sha1">apache2.sha1( - request_rec<em> r</em>, string<em> string</em> - ) - </a></h3> - -<p> -Computes an SHA-1 digest sum based on a string (binary safe) - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>string</td> -<td>The (binary) string to digest</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The SHA-1 digest sum of the data provided - </p> -<p> -<em>Example:</em> -</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> </p> - -<h3><a name="apache2.unescape" id="apache2.unescape">apache2.unescape( - request_rec<em> r</em>, string<em> string</em> - ) - </a></h3> - -<p> -unescapes an URL-escaped string - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>string</td> -<td>The string to unescape</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The URL-unescaped string - </p> -<p> -<em>Example:</em> -</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> </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.requestbody">apache2.requestbody</a> -<br /> -<a href="#apache2.add_input_filter">apache2.add_input_filter</a> -<br /> -<a href="#apache2.get_basic_auth_pw">apache2.get_basic_auth_pw</a> -<br /> -<a href="#apache2.set_document_root">apache2.set_document_root</a> -<br /> -<a href="#apache2.set_context_prefix">apache2.set_context_prefix</a> -<br /> -<a href="#apache2.get_server_name_for_url">apache2.get_server_name_for_url</a> -<br /> -<a href="#apache2.set_keepalive">apache2.set_keepalive</a> -<br /> -<a href="#apache2.make_etag">apache2.make_etag</a> -<br /> -<a href="#apache2.send_interim_response">apache2.send_interim_response</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> - ) - </a></h3> - -<p> -Adds an input filter to the request - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>filter</td> -<td>The name of the filter handler to add</td> -</tr> -</table> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -apache2.add_input_filter(r, "SPAM_FILTER") -- Check input for spam..? - </pre> - -<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> - ) - </a></h3> - -<p> -Returns the password from a basic authorization request or nil if none was supplied - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The password from a basic authorization request or nil if none was supplied - </p> -<p> </p> - -<h3><a name="apache2.get_server_name_for_url" id="apache2.get_server_name_for_url">apache2.get_server_name_for_url( - request_rec<em> r</em> - ) - </a></h3> - -<p> -Get the current server name from the request for the purposes of using in a URL. -If the server name is an IPv6 literal address, it will be returned in URL format (e.g., "[fe80::1]"). - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -</table> -<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> - ) - </a></h3> - -<p> -Constructs an entity tag from the resource information. If it's a real file, build in some of the file characteristics. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>force_weak</td> -<td>force_weak Force the entity tag to be weak - it could be modified again in as short an interval.</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The entity tag - </p> -<p> </p> - -<h3><a name="apache2.requestbody" id="apache2.requestbody">apache2.requestbody( - request_rec<em> r</em>, number<em> size</em>, string<em> filename</em> - ) - </a></h3> - -<p> -Reads the request body. If a filename is specified, the request body will be written to that file and the number of bytes written returned, otherwise, the full request body will be returned as a string. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>size</td> -<td>The maximum size allowed, or 0/nil for unlimited size</td> -</tr> -<tr> -<td>filename</td> -<td>The file to save the output to, or nil to return it as a string</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The number of bytes written if a filename was specified, otherwise it returns the entire request body as a string. - </p> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -if tonumber(r.headers_in['Content-Length'] or 0) < 10000 then - local smallfile = apache2.requestbody(r, 10000) -- fetch a small file into memory - r:puts("I saved the uploaded file in memory") -else - local read = apache2.requestbody(r, 0, "/path/to/tmp") - r:puts("I saved the uploaded file in a temp directory. Total bytes written was: ", read) -end - </pre> - -<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> - ) - </a></h3> - -<p> -Sends an interim (HTTP 1xx) response immediately. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>send_headers</td> -<td>send_headers Whether to send&clear headers in r->headers_out</td> -</tr> -</table> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -apache2.send_interim_response(r, false) - </pre> - -<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> - ) - </a></h3> - -<p> -Set context_prefix and context_document_root for a request. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>prefix</td> -<td>The URI prefix, without trailing slash</td> -</tr> -<tr> -<td>document</td> -<td>The corresponding directory on disk, without trailing slash</td> -</tr> -</table> -<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> - ) - </a></h3> - -<p> -Sets the document root of the request. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>root</td> -<td>root</td> -</tr> -</table> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> --- Suppose our real document root is /var/bar, then... -if r.hostname == "www.foo.com" then - apache2.set_document_root(r, "/www/foo") -- change document root on the fly -end - </pre> - -<p> </p> - -<h3><a name="apache2.set_keepalive" id="apache2.set_keepalive">apache2.set_keepalive( - request_rec<em> r</em> - ) - </a></h3> - -<p> -Sets the keepalive status for this request - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -True if keepalive can be set, false otherwise - </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="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> - ) - </a></h3> - -<p> -Evaluates an ap_expr (think <If ...>) expression and returns true if the expression is true, false otherwise. A second value containing an error string is returned if the expression is invalid. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>expression</td> -<td>expression</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -True if the expression evaluates as true, false if the expression doesn't evaluate as true or if an error occurred. If an error occurred during parsing, a second value will be returned, containng the error string. - </p> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -if apache2.expr("%{REQUEST_URI} =~ /force-gzip") then - r:addoutputfilter("DEFLATE") -end - </pre> - -<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> - ) - </a></h3> -<p> -Evaluates a regular expression and, if it matches the source string, captures the variables and returns the matches as a table. On error, it returns nil. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>expression</td> -<td>expression to match for</td> -</tr> -<tr> -<td>source</td> -<td>the source string to capture from</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -True if the expression evaluates as true, false if the expression doesn't evaluate as true or if an error occurred. If an error occurred during parsing, a second value will be returned, containng the error string. - </p> -<p> -<em>Example:</em> -</p> <pre class="prettyprint lang-lua"> -local matches = apache2.regex(r, [[(\S+) kitty]], "Hello kitty") -if matches and matches[1] then - r:puts("You said ", matches[1], " to kitty") -end - </pre> - -<p> </p> +--[[ + This script uses a basic IVM table to determine where to + send the request. +]]-- -<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> - ) - </a></h3> +local backends = { + “http://backend1.foo.com/“, + “http://backend2.foo.com/“, + “http://backend3.foo.com/“ +} -<p> -Determines if a string matches a pattern containing the wildcards '?' or '*' - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>str</td> -<td>The string to check</td> -</tr> -<tr> -<td>expexted</td> -<td>The pattern to match against</td> -</tr> -<tr> -<td>ignoreCase</td> -<td>Whether to ignore case when matching</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -True if the two strings match, false otherwise. - </p> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -if apache2.strcmp_match("foo.bar", "foo.*") then - r:puts("It matches!") +function pick_backend(r) + local chosen_backend = 1 -- default to backend1 + local lowest_count = nil + for i = 1, #backends, 1 do -- Loop through all backends + local count = r:ivm_get("proxy_request_count_" .. i) + if not count then -- If this backend hasn't been used at all, prefer it + chosen_backend = i + lowest_count = 0 + break + end + if not lowest_count or lowest_count > count then -- If this backend has had less requests, pick it for now + chosen_backend = i + lowest_count = count + end + end + lowest_count = lowest_count + 1 + r:ivm_set("proxy_request_count_" .. chosen_backend, lowest_count) + return chosen_backend end - </pre> -<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.mpm_query">apache2.mpm_query</a> -<br /> -<a href="#apache2.terminate">apache2.terminate</a> -<br /> -<a href="#apache2.scoreboard_process">apache2.scoreboard_process</a> -<br /> -<a href="#apache2.scoreboard_worker">apache2.scoreboard_worker</a> -<br /> -<a href="#apache2.module_info">apache2.module_info</a> -<br /> -<a href="#apache2.loaded_modules">apache2.loaded_modules</a> -<br /> -<a href="#apache2.runtime_dir_relative">apache2.runtime_dir_relative</a> -<br /> -<a href="#apache2.server_info">apache2.server_info</a> -<br /> -<a href="#apache2.state_query">apache2.state_query</a> -<br /> -<a href="#apache2.custom_response">apache2.custom_response</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> - ) - </a></h3> - -<p> -Adds a component to the server description and banner strings - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>component</td> -<td>The component to add</td> -</tr> -</table> -<p> -<em>Example:</em> -</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") +function proxy_handler(r) + local backend = pick_backend(r) -- Pick a backend based on no. of requests served + r.handler = "proxy-server" + r.proxyreq = apache2.PROXYREQ_REVERSE + r.filename = "proxy:" .. backends[backend] .. r.uri + return apache2.DECLINED -- let the proxy handler do this instead end - </pre> - -<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> - ) - </a></h3> - -<p> -Install a custom response handler for a given status - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>status</td> -<td>The status for which the custom response should be used</td> -</tr> -<tr> -<td>string</td> -<td>The custom response. This can be a static string, a file or a URL</td> -</tr> -</table> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -apache2.custom_response(r, 404, "Not found!!") - </pre> - -<p> </p> - -<h3><a name="apache2.exists_config_define" id="apache2.exists_config_define">apache2.exists_config_define( - string<em> name</em> - ) - </a></h3> - -<p> -Checks for a definition from the server command line - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>name</td> -<td>The define to check for</td> -</tr> -</table> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -if apache2.exists_config_define("FOO") then - r:puts("This server was started with -DFOO") -end - </pre> - -<p> </p> - -<h3><a name="apache2.loaded_modules" id="apache2.loaded_modules">apache2.loaded_modules( - - ) - </a></h3> - -<p> -Returns a table containing the name (c filename) of all loaded modules - </p> -<p> -<em>Arguments:</em> -</p> -<p>None</p> -<p> -<em>Return value(s):</em> -<br /> -A table containing the name (c filename) of all loaded modules - </p> -<p> </p> - -<h3><a name="apache2.module_info" id="apache2.module_info">apache2.module_info( - string<em> c</em>, string<em> file</em> - ) - </a></h3> - -<p> -Returns information about a specific module (if loaded) - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>c</td> -<td>c</td> -</tr> -<tr> -<td>file</td> -<td>file</td> -</tr> -</table> -<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> -<p> </p> - -<h3><a name="apache2.mpm_query" id="apache2.mpm_query">apache2.mpm_query( - number<em> i</em> - ) - </a></h3> - -<p> -Queries the MPM for a specific value - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>i</td> -<td>i</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The queried value - </p> -<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> - ) - </a></h3> - -<p> -Returns the path of a file relative to the default runtime directory - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>file</td> -<td>file</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The path of a file relative to the default runtime directory - </p> -<p> </p> - -<h3><a name="apache2.scoreboard_process" id="apache2.scoreboard_process">apache2.scoreboard_process( - request_rec<em> r</em>, number<em> child</em> - ) - </a></h3> - -<p> -Returns the scoreboard for a server daemon as a table - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>child</td> -<td>The server child to query</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The scoreboard for a server daemon as a table - </p> -<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> - ) - </a></h3> - -<p> -Returns the scoreboard for a single thread as a table - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>child</td> -<td>The server child to query</td> -</tr> -<tr> -<td>thread</td> -<td>The thread to query</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The scoreboard for a single thread as a table - </p> -<p> </p> - -<h3><a name="apache2.server_info" id="apache2.server_info">apache2.server_info( - - ) - </a></h3> - -<p> -Returns a table with information about the server program - </p> -<p> -<em>Arguments:</em> -</p> -<p>None</p> -<p> -<em>Return value(s):</em> -<br /> -A table with information about the server program - </p> -<p> </p> - -<h3><a name="apache2.state_query" id="apache2.state_query">apache2.state_query( - number<em> field</em> - ) - </a></h3> - -<p> -Query the server for some state information - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>field</td> -<td>Which information is requested</td> -</tr> -</table> -<p> -<em>Example:</em> -</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> </p> - -<h3><a name="apache2.terminate" id="apache2.terminate">apache2.terminate( - - ) - </a></h3> - -<p> -Kills off a server process. This has no other use than to show how dangerous mod_lua can be ;) - </p> -<p> -<em>Arguments:</em> -</p> -<p>None</p> -<p> </p> +</pre> </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:do">db:do</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> - +<h2><a name="map_handler" id="map_handler">Example 6: Overlays using LuaMapHandler</a></h2> <p> -Opens up a new database connection. See the DB functions for mod_pLua for more info on this. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>dbtype</td> -<td>dbtype</td> -</tr> -<tr> -<td>conn_string</td> -<td>connection string</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -The database connection as a table with functions, or nil if the connection failed. If a connection failed, a second argument (string) with the error code is returned. - </p> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -local db, error = apache2.dbopen(r, "mod_dbd") -if error then - r:puts("DB error: ", error) -else - -- DB stuff here -end - </pre> - -<p> </p> - -<h3><a name="db:close" id="db:close">db:close( - request_rec<em> r</em> - ) - </a></h3> - -<p> -Closes a database connection - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -</table> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -local db = apache2.dbopen(r, "mod_dbd") -- open a db connection -db:close() -- close it down - </pre> - -<p> </p> - -<h3><a name="db:do" id="db:do">db:do( - request_rec<em> r</em>, string<em> query</em> - ) - </a></h3> - -<p> -Executes a statement that doesn't return a result set - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>query</td> -<td>The SQL statement to execute</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -If the statement is valid, a table of results are returned. If an error occurred, the first return value is false and the second return value is a string containing an error message. - </p> -<p> -<em>Example:</em> -</p> -<pre class="prettyprint lang-lua"> -local db = apache2.dbopen(r, "mod_dbd") -local affected = db:do("DELETE FROM `table` WHERE 1") -if affected then - r:puts("Affected ", affected, " rows") -end - </pre> - -<p> </p> - -<h3><a name="db:query" id="db:query">db:query( - request_rec<em> r</em>, string<em> query</em> - ) - </a></h3> - -<p> -Queries the database for information using the specified statement. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>r</td> -<td>The mod_lua request handle</td> -</tr> -<tr> -<td>query</td> -<td>The SQL statement to execute</td> -</tr> -</table> -<p> -<em>Return value(s):</em> -<br /> -If the statement is valid, a table of results are returned. If an error occurred, the first return value is false and the second return value is a string containing an error message. - </p> -<p> -<em>Example:</em> +Coming soon! </p> -<pre class="prettyprint lang-lua"> -local db = apache2.dbopen(r, "mod_dbd") -local result, error = db:query("SELECT * FROM `table` WHERE 1") -if result then - for key, value in pairs(result) - r:puts( ("row %s: %s\n"):format(key, table.concat(value, ", ")) ) - end -end - </pre> - -<p> </p> +<pre class="prettyprint lang-config"> +LuaMapHandler ^/portal/([a-z]+)/ /path/to/lua/script.lua handle_$1 +</pre> </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( - - ) - </a></h3> - -<p> -Returns the current time in microseconds. - </p> -<p> -<em>Arguments:</em> -</p> -<p>None</p> -<p> -<em>Return value(s):</em> -<br /> -The current time in microseconds. - </p> -<p> </p> - -<h3><a name="apache2.sleep" id="apache2.sleep">apache2.sleep( - number<em> seconds</em> - ) - </a></h3> - -<p> -Sleeps for a while. Floating point values can be used to sleep for less than a second. - </p> -<p> -<em>Arguments:</em> -</p> -<table class="bordered"> -<tr> -<th>Argument</th> -<th>Description</th> -</tr> -<tr> -<td>seconds</td> -<td>The number of seconds to sleep.</td> -</tr> -</table> +<h2><a name="mod_status_lua" id="mod_status_lua">Example 6: Basic Lua scripts</a></h2> <p> -<em>Example:</em> +Also coming soon </p> -<pre class="prettyprint lang-lua"> -r:puts("this is ") -apache2.flush(r) -apache2.sleep(0.25) -- sleep for a quarter second. -r:puts("delayed") - </pre> - -<p> </p> - </div></div> <div class="bottomlang"> <p><span>Available Languages: </span><a href="../en/developer/lua.html" title="English"> en </a></p> diff --git a/docs/manual/mod/event.html.en b/docs/manual/mod/event.html.en index f2f1c72ccb..46ab1efcf6 100644 --- a/docs/manual/mod/event.html.en +++ b/docs/manual/mod/event.html.en @@ -95,10 +95,11 @@ of consuming threads only for connections with active processing</td></tr> status page of <code class="module"><a href="../mod/mod_status.html">mod_status</a></code> shows how many connections are in the mentioned states.</p> - <p>The improved connection handling does not yet work for certain - connection filters, in particular SSL. For SSL connections, this MPM will - fall back to the behaviour of the <code class="module"><a href="../mod/worker.html">worker</a></code> MPM and - reserve one worker thread per connection.</p> + <p>The improved connection handling may not work for certain connection + filters that have declared themselves as incompatible with event. In these + cases, this MPM will fall back to the behaviour of the + <code class="module"><a href="../mod/worker.html">worker</a></code> MPM and reserve one worker thread per connection. + All modules shipped with the server are compatible with the event MPM.</p> <p>The MPM assumes that the underlying <code>apr_pollset</code> implementation is reasonably threadsafe. This enables the MPM to @@ -150,10 +151,10 @@ of consuming threads only for connections with active processing</td></tr> </table> <p>The event MPM handles some connections in an asynchronous way, where request worker threads are only allocated for short periods of time as - needed, and other (mostly SSL) connections with one request worker thread - reserved per connection. This can lead to situations where all workers are - tied up and no worker thread is available to handle new work on established - async connections.</p> + needed, and other connections with one request worker thread reserved per + connection. This can lead to situations where all workers are tied up and + no worker thread is available to handle new work on established async + connections.</p> <p>To mitigate this problem, the event MPM does two things: Firstly, it limits the number of connections accepted per process, depending on the diff --git a/docs/manual/mod/event.html.fr b/docs/manual/mod/event.html.fr index 5e22cc102e..e05f0b33e6 100644 --- a/docs/manual/mod/event.html.fr +++ b/docs/manual/mod/event.html.fr @@ -101,10 +101,12 @@ mobiliser des threads que pour les connexions en cours de traitement</td></tr> <code class="module"><a href="../mod/mod_status.html">mod_status</a></code> montre les connexions qui se trouvent dans les situations mentionnées.</p> - <p>Le gestionnaire de connexion amélioré ne fonctionne pas encore - pour certains filtres de connexion, et en particulier SSL. Pour les - connexions SSL, ce MPM réadopte le comportement du MPM - <code class="module"><a href="../mod/worker.html">worker</a></code> et réserve un thread par connexion.</p> + <p>Le gestionnaire de connexion amélioré peut ne pas + fonctionner pour les filtres de connexion qui se déclarent eux-mêmes + comme incompatibles avec le MPM event. Dans ce cas, le MPM event + adopte le comportement du MPM <code class="module"><a href="../mod/worker.html">worker</a></code> et + réserve un thread par connexion. Tous les modules fournis + avec le serveur sont compatibles avec le MPM event.</p> <p>Le MPM présuppose que l'implémentation <code>apr_pollset</code> sous-jacente est raisonnablement sûre du point de vue des threads. @@ -161,8 +163,8 @@ mobiliser des threads que pour les connexions en cours de traitement</td></tr> </table> <p>Le MPM event gère certaines connexions de manière asynchrone ; dans ce cas, les threads traitant la requête sont alloués selon les - besoins et pour de courtes périodes. Dans les autres cas (la plupart - du temps pour les connexions SSL), un thread est réservé par + besoins et pour de courtes périodes. Dans les autres cas, un + thread est réservé par connexion. Ceci peut conduire à des situations où tous les threads sont saturés et où aucun thread n'est capable d'effectuer de nouvelles tâches pour les connexions asynchrones établies.</p> diff --git a/docs/manual/mod/mod_lua.html.fr b/docs/manual/mod/mod_lua.html.fr index 9c13200e24..53a00d51bb 100644 --- a/docs/manual/mod/mod_lua.html.fr +++ b/docs/manual/mod/mod_lua.html.fr @@ -714,7 +714,7 @@ while nous_avons_des_donn r:puts("Bla bla bla\n") -- envoi des données à envoyer vers le tampon r:flush() -- vidage du tampon (envoi au client) r:sleep(0.5) -- mise en attente et bouclage -+end +end </pre> @@ -736,23 +736,24 @@ end <pre class="prettyprint lang-lua"> -r:parseargs() -- renvoie une table Lua contenant la chaîne -d'arguments de la requête +r:parseargs() -- renvoie deux tables : une table standard de couples +clé/valeur pour les données GET simples, et une autre pour les données +multivaluées (par exemple foo=1&foo=2&foo=3) : -local GET = r:parseargs() -+r:puts("Votre nom est : " .. GET['name'] or "Unknown") +local GET, GETMULTI = r:parseargs() +r:puts("Votre nom est : " .. GET['name'] or "Unknown") </pre> <pre class="prettyprint lang-lua"> r:parsebody()([sizeLimit]) -- interprète le corps de la requête -en tant que POST et renvoie une table lua. Un nombre optionnel +en tant que POST et renvoie deux tables lua, comme r:parseargs(). Un nombre optionnel peut être fourni pour spécifier le nombre maximal d'octets à interpréter. La valeur par défaut est 8192. -local POST = r:parsebody(1024*1024) -+r:puts("Votre nom est : " .. POST['name'] or "Unknown") +local POST, POSTMULTI = r:parsebody(1024*1024) +r:puts("Votre nom est : " .. POST['name'] or "Unknown") </pre> diff --git a/docs/manual/mod/mod_lua.xml.meta b/docs/manual/mod/mod_lua.xml.meta index 8fc1a0efdf..b55c7710e9 100644 --- a/docs/manual/mod/mod_lua.xml.meta +++ b/docs/manual/mod/mod_lua.xml.meta @@ -8,6 +8,6 @@ <variants> <variant>en</variant> - <variant outdated="yes">fr</variant> + <variant>fr</variant> </variants> </metafile>