This document expands on the 
Stuff about what 
This document will discuss how you can bla bla bla. In the first chapter, we will bla bla
In the second part of this document, we will be looking at bla bla bla
First and foremost, you are expected to have a basic knowledge of how the Lua programming language works. In most cases, we will try to be as pedagogical as possible and link to documents describing the functions used in the examples, but there are also many cases where it is necessary to either just assume that "it works" or do some digging yourself into what the hows and whys of various function calls.
bla bla
bla bla
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:
Encodes a string using the base64 encoding scheme.
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
| string | The string to encode | 
Example:
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:
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:
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:
convert an OS path to a URL in an OS dependant 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:
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:
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:
apache2.sendfile
apache2.port
apache2.getenv
apache2.setenv
apache2.options
apache2.allowoverrides
apache2.requestbody
apache2.add_input_filter
apache2.add_output_filter
apache2.get_basic_auth_pw
apache2.get_limit_req_body
apache2.request_has_body
apache2.set_document_root
apache2.some_auth_required
apache2.context_document_root
apache2.context_prefix
apache2.set_context_prefix
apache2.set_keepalive
apache2.make_etag
apache2.flush
apache2.send_interim_response
apache2.get_server_name
apache2.auth_type
apache2.auth_name
apache2.satisfies
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:
Adds an output filter to the request
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
| filter | The name of the filter handler to add | 
Example:
Returns the currently allowed overrides for this context (AuthCfg, Options etc)
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The currently allowed overrides for this context (AuthCfg, Options etc)
        
Example:
Returns the current Authorization realm
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The current authorization realm
        
Returns the current authentication type used in the request
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The current Authorization type used in the request
        
Get the context_document_root for a request. This is a generalization of the document root, which is too limited in the presence of mappers like mod_userdir and mod_alias. The context_document_root is the directory on disk that maps to the context_prefix URI prefix.
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Get the context_prefix for a request. The context_prefix URI prefix maps to the context_document_root on disk.
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Flushes the content buffer, writing everything to the client immediately.
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Example:
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
        
Returns the current request body size limit
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The current request body size limit
        
Example:
Returns the current server name from the request
Arguments:
None
Return value(s):
The server name
        
Example:
Returns the value of an environment variable
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
| key | key | 
Return value(s):
The queried value
        
Example:
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
        
Returns the currently allowed options for this context (Indexes, MultiViews etc)
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The currently allowed options for this context.
        
Example:
Returns the port currently being used by the request
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The current port used by the request
        
Example:
Returns true if the request has a body(POST/PUT), false otherwise
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
True if the request has a body(POST/PUT), false otherwise
        
Example:
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 | 
| filename | filename | 
Return value(s):
The number of bytes written if a filename was specified, otherwise it returns the entire request body as a string.
        
Example:
Returns how the requires lines must be met.
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
How the requirements must be met (SATISFY_ANY, SATISFY_ALL, SATISFY_NOSPEC).
        
Example:
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:
Sends a file to the client via sendfile() if possible.
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
| filename | The file to send | 
Example:
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:
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
        
Sets the value of an environment variable
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
| key | key | 
| val | val | 
Example:
Returns true if authorization is required for this request
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
True if auth is required, false if not.
        
Example:
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:
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:
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:
apache2.add_version_component
apache2.banner
apache2.mpm_query
apache2.terminate
apache2.scoreboard_process
apache2.scoreboard_worker
apache2.started
apache2.module_info
apache2.get_server_built
apache2.is_initial_req
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:
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:
Checks for a definition from the server command line
Arguments:
| Argument | Description | 
|---|---|
| name | The define to check for | 
Example:
Returns the date the server was built
Arguments:
None
Return value(s):
The date the server was built
        
Returns true if this is the main request, false if it is a sub-request
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
True if this is the main request, false if it is a sub-request
        
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
        
Returns the time when the server was (re)started
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Return value(s):
The time when the server was (re)started
        
Query the server for some state information
Arguments:
| Argument | Description | 
|---|---|
| field | Which information is requested | 
Example:
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.
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:
Closes a database connection
Arguments:
| Argument | Description | 
|---|---|
| r | The mod_lua request handle | 
Example:
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:
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:
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: