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 @@
Example 2: Mass virtual hosting
Example 3: A basic authorization hook
Example 4: Authorization using LuaAuthzProvider
Example 5: Overlays using LuaMapHandler
Example 5: A rudimentary load balancer
Example 6: Overlays using LuaMapHandler
Example 6: Basic Lua scripts
HTTPd bindings: String manipulation
HTTPd bindings: Request handling
HTTPd bindings: Parser functions
HTTPd bindings: Server settings
HTTPd bindings: Database connectivity
HTTPd bindings: Miscellaneous+ 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: +
++LuaHookTranslateName /path/to/script.lua proxy_handler ++ + +
+--[[
+ This script uses a basic IVM table to determine where to
+ send the request.
+]]--
+
+local backends = {
+ “http://backend1.foo.com/“,
+ “http://backend2.foo.com/“,
+ “http://backend3.foo.com/“
+}
+
+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
+
+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
+
+
+Coming soon!
@@ -542,1478 +592,6 @@ LuaMapHandler ^/portal/([a-z]+)/ /path/to/lua/script.lua handle_$1Also coming soon
-
-apache2.base64_encode
-
-apache2.base64_decode
-
-apache2.escape
-
-apache2.unescape
-
-apache2.escapehtml
-
-apache2.md5
-
-apache2.sha1
-
-apache2.os_escape_path
-
-apache2.escape_logitem
-
-
-Decodes a base64-encoded string -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| string | -The string to decode | -
-Return value(s):
-
-The base64-decoded string.
-
-Example: -
--local str = "This is a test" -local encoded = apache2.base64_encode(str) -local decoded = apache2.base64_decode(encoded) -- -
- -
-Encodes a string using the base64 encoding scheme. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| string | -The string to encode | -
-Example: -
--local str = "This is a test" -local encoded = apache2.base64_encode(str) -local decoded = apache2.base64_decode(encoded) -- -
- -
-url-escapes a string -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| string | -The string to escape | -
-Return value(s):
-
-The URL-escaped string.
-
-Example: -
--local str = "This is a test" -local escaped = apache2.escape(str) -print(escaped) -- prints "This+is+a+test" -- -
- -
-Escape a string for logging -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| path | -The string to escape | -
-Return value(s):
-
-The converted string
-
- -
-Escapes HTML entities. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| html | -The HTML code to escape | -
| toasc | -Whether to escape all non-ASCI characters as &#nnn; | -
-Return value(s):
-
-The escaped HTML code.
-
-Example: -
--local html = "<b>Testing!</b>" -local escaped = apache2.escapehtml(html) -r:puts(escaped) -- prints "<b>Testing!</b>" -- -
- -
-Computes an MD5 digest sum based on a string (binary safe) -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| string | -The (binary) string to digest | -
-Return value(s):
-
-The MD5 digest sum of the data provided
-
-Example: -
--local text = "The quick brown fox jumps over the lazy dog" -local md5 = apache2.md51(text) -r:puts(md5) -- prints out "9e107d9d372bb6826bd81d3542a419d6" -- -
- -
-convert an OS path to a URL in an OS dependent way. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| path | -The path to convert | -
| partial | -partial if set, assume that the path will be appended to something with a '/' in it (and thus does not prefix "./") | -
-Return value(s):
-
-The converted URL
-
-Example: -
-
-local path = ap_os_escape_path("C:/foo/bar.txt")
-
-
-- -
-Computes an SHA-1 digest sum based on a string (binary safe) -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| string | -The (binary) string to digest | -
-Return value(s):
-
-The SHA-1 digest sum of the data provided
-
-Example: -
--local text = "The quick brown fox jumps over the lazy dog" -local sha1 = apache2.sha1(text) -r:puts(sha1) -- prints out "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12" -- -
- -
-unescapes an URL-escaped string -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| string | -The string to unescape | -
-Return value(s):
-
-The URL-unescaped string
-
-Example: -
--local str = "This+is+a+test" -local unescaped = apache2.unescape(str) -print(unescaped) -- prints "This is a test" -- -
- -
-apache2.requestbody
-
-apache2.add_input_filter
-
-apache2.get_basic_auth_pw
-
-apache2.set_document_root
-
-apache2.set_context_prefix
-
-apache2.get_server_name_for_url
-
-apache2.set_keepalive
-
-apache2.make_etag
-
-apache2.send_interim_response
-
-
-Adds an input filter to the request -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| filter | -The name of the filter handler to add | -
-Example: -
--apache2.add_input_filter(r, "SPAM_FILTER") -- Check input for spam..? -- -
- -
-Returns the password from a basic authorization request or nil if none was supplied -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
-Return value(s):
-
-The password from a basic authorization request or nil if none was supplied
-
- -
-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]"). -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
- -
-Constructs an entity tag from the resource information. If it's a real file, build in some of the file characteristics. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| force_weak | -force_weak Force the entity tag to be weak - it could be modified again in as short an interval. | -
-Return value(s):
-
-The entity tag
-
- -
-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. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| size | -The maximum size allowed, or 0/nil for unlimited size | -
| filename | -The file to save the output to, or nil to return it as a string | -
-Return value(s):
-
-The number of bytes written if a filename was specified, otherwise it returns the entire request body as a string.
-
-Example: -
-
-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
-
-
-- -
-Sends an interim (HTTP 1xx) response immediately. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| send_headers | -send_headers Whether to send&clear headers in r->headers_out | -
-Example: -
--apache2.send_interim_response(r, false) -- -
- -
-Set context_prefix and context_document_root for a request. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| prefix | -The URI prefix, without trailing slash | -
| document | -The corresponding directory on disk, without trailing slash | -
- -
-Sets the document root of the request. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| root | -root | -
-Example: -
---- 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 -- -
- -
-Sets the keepalive status for this request -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
-Return value(s):
-
-True if keepalive can be set, false otherwise
-
- -
-apache2.expr
-
-apache2.regex
-
-apache2.strcmp_match
-
-
-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. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| expression | -expression | -
-Return value(s):
-
-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.
-
-Example: -
-
-if apache2.expr("%{REQUEST_URI} =~ /force-gzip") then
- r:addoutputfilter("DEFLATE")
-end
-
-
-- -
-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. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| expression | -expression to match for | -
| source | -the source string to capture from | -
-Return value(s):
-
-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.
-
-Example: -
-
-local matches = apache2.regex(r, [[(\S+) kitty]], "Hello kitty")
-if matches and matches[1] then
- r:puts("You said ", matches[1], " to kitty")
-end
-
-
-- -
-Determines if a string matches a pattern containing the wildcards '?' or '*' -
--Arguments: -
-| Argument | -Description | -
|---|---|
| str | -The string to check | -
| expexted | -The pattern to match against | -
| ignoreCase | -Whether to ignore case when matching | -
-Return value(s):
-
-True if the two strings match, false otherwise.
-
-Example: -
-
-if apache2.strcmp_match("foo.bar", "foo.*") then
- r:puts("It matches!")
-end
-
-
-- -
-apache2.add_version_component
-
-apache2.mpm_query
-
-apache2.terminate
-
-apache2.scoreboard_process
-
-apache2.scoreboard_worker
-
-apache2.module_info
-
-apache2.loaded_modules
-
-apache2.runtime_dir_relative
-
-apache2.server_info
-
-apache2.state_query
-
-apache2.custom_response
-
-apache2.exists_config_define
-
-
-Adds a component to the server description and banner strings -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| component | -The component to add | -
-Example: -
-
-if not apache2.banner():match("FooModule") then -- Make sure we haven't added it already
- apache2.add_version_component(r, "FooModule/1.0")
-end
-
-
-- -
-Install a custom response handler for a given status -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| status | -The status for which the custom response should be used | -
| string | -The custom response. This can be a static string, a file or a URL | -
-Example: -
--apache2.custom_response(r, 404, "Not found!!") -- -
- -
-Checks for a definition from the server command line -
--Arguments: -
-| Argument | -Description | -
|---|---|
| name | -The define to check for | -
-Example: -
-
-if apache2.exists_config_define("FOO") then
- r:puts("This server was started with -DFOO")
-end
-
-
-- -
-Returns a table containing the name (c filename) of all loaded modules -
--Arguments: -
-None
-
-Return value(s):
-
-A table containing the name (c filename) of all loaded modules
-
- -
-Returns information about a specific module (if loaded) -
--Arguments: -
-| Argument | -Description | -
|---|---|
| c | -c | -
| file | -file | -
-Return value(s):
-
-The various commands available to this module as a table, or nil if the module wasn't found.
-
- -
-Queries the MPM for a specific value -
--Arguments: -
-| Argument | -Description | -
|---|---|
| i | -i | -
-Return value(s):
-
-The queried value
-
- -
-Returns the path of a file relative to the default runtime directory -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| file | -file | -
-Return value(s):
-
-The path of a file relative to the default runtime directory
-
- -
-Returns the scoreboard for a server daemon as a table -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| child | -The server child to query | -
-Return value(s):
-
-The scoreboard for a server daemon as a table
-
- -
-Returns the scoreboard for a single thread as a table -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| child | -The server child to query | -
| thread | -The thread to query | -
-Return value(s):
-
-The scoreboard for a single thread as a table
-
- -
-Returns a table with information about the server program -
--Arguments: -
-None
-
-Return value(s):
-
-A table with information about the server program
-
- -
-Query the server for some state information -
--Arguments: -
-| Argument | -Description | -
|---|---|
| field | -Which information is requested | -
-Example: -
-
-local gen = apache2.state_query(2)
-r:puts("This is generation no. " .. gen .. " of the top-level parent")
-
-
-- -
-Kills off a server process. This has no other use than to show how dangerous mod_lua can be ;) -
--Arguments: -
-None
-- -
-apache2.dbopen
-
-db:query
-
-db:do
-
-db:close
-
-
-Opens up a new database connection. See the DB functions for mod_pLua for more info on this. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| dbtype | -dbtype | -
| conn_string | -connection string | -
-Return value(s):
-
-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.
-
-Example: -
-
-local db, error = apache2.dbopen(r, "mod_dbd")
-if error then
- r:puts("DB error: ", error)
-else
- -- DB stuff here
-end
-
-
-- -
-Closes a database connection -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
-Example: -
--local db = apache2.dbopen(r, "mod_dbd") -- open a db connection -db:close() -- close it down -- -
- -
-Executes a statement that doesn't return a result set -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| query | -The SQL statement to execute | -
-Return value(s):
-
-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.
-
-Example: -
-
-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
-
-
-- -
-Queries the database for information using the specified statement. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| r | -The mod_lua request handle | -
| query | -The SQL statement to execute | -
-Return value(s):
-
-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.
-
-Example: -
-
-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
-
-
-- -
-apache2.clock
-
-apache2.sleep
-
-
-Returns the current time in microseconds. -
--Arguments: -
-None
-
-Return value(s):
-
-The current time in microseconds.
-
- -
-Sleeps for a while. Floating point values can be used to sleep for less than a second. -
--Arguments: -
-| Argument | -Description | -
|---|---|
| seconds | -The number of seconds to sleep. | -
-Example: -
-
-r:puts("this is ")
-apache2.flush(r)
-apache2.sleep(0.25) -- sleep for a quarter second.
-r:puts("delayed")
-
-
--
Available Languages: en
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 status page ofmod_status shows how many connections are
in the mentioned states.
- 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 worker MPM and
- reserve one worker thread per connection.
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
+ worker MPM and reserve one worker thread per connection.
+ All modules shipped with the server are compatible with the event MPM.
The MPM assumes that the underlying apr_pollset
implementation is reasonably threadsafe. This enables the MPM to
@@ -150,10 +151,10 @@ of consuming threads only for connections with active processing
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.
+ 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.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
mod_status montre les connexions qui se trouvent
dans les situations mentionnées.
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
- worker et réserve un thread par connexion.
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 worker et
+ réserve un thread par connexion. Tous les modules fournis
+ avec le serveur sont compatibles avec le MPM event.
Le MPM présuppose que l'implémentation apr_pollset
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
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.
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 @@ -736,23 +736,24 @@ end
-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")
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")
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 @@