1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

mod_lua: Add a lot of core httpd/apr functionality to mod_lua

(such as regex matching, expr evaluation, changing/fetching server configuration/info - see docs for a complete list).
This also includes a bunch of automatically scraped functions, which may or may not be super useful.
Comments appreciated as always, especially on the more hacky bits.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1420377 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Gruno
2012-12-11 20:08:24 +00:00
parent 1a50285096
commit 3b6cdb0f92
4 changed files with 1208 additions and 3 deletions

View File

@@ -647,6 +647,153 @@ r:parsebody([sizeLimit]) -- parse the request body as a POST and return a lua ta
<highlight language="lua">
r:escape_html("&lt;html&gt;test&lt;/html&gt;") -- Escapes HTML code and returns the escaped result
</highlight>
<highlight language="lua">
r:base64_encode(string) -- Encodes a string using the Base64 encoding standard
</highlight>
<highlight language="lua">
r:base64_decode(string) -- Decodes a Base64-encoded string
</highlight>
<highlight language="lua">
r:md5(string) -- Calculates and returns the MD5 digest of a string (binary safe)
</highlight>
<highlight language="lua">
r:sha1(string) -- Calculates and returns the SHA1 digest of a string (binary safe)
</highlight>
<highlight language="lua">
r:escape(string) -- URL-Escapes a string
</highlight>
<highlight language="lua">
r:unescape(string) -- Unescapes an URL-escaped string
</highlight>
<highlight language="lua">
r:banner() -- Returns the current server banner
</highlight>
<highlight language="lua">
r:port() -- Returns the current server port used for the request
</highlight>
<highlight language="lua">
r:mpm_query(number) -- Queries the server for MPM information using ap_mpm_query
</highlight>
<highlight language="lua">
r:expr(string) -- Evaluates an <a href="../expr.html">expr</a> string.
</highlight>
<highlight language="lua">
r:scoreboard_process(a) -- Queries the server for information about the process at position <code>a</code>
</highlight>
<highlight language="lua">
r:scoreboard_worker(a, b) -- Queries for information about the worker thread, <code>b</code>, in process <code>a</code>
</highlight>
<highlight language="lua">
r:started() -- Returns the time of the last server (re)start
</highlight>
<highlight language="lua">
r:clock() -- Returns the current time with microsecond precision
</highlight>
<highlight language="lua">
r:requestbody(filename) -- Reads and returns the request body of a request.
-- If 'filename' is specified, it instead saves the
-- contents to that file.
</highlight>
<highlight language="lua">
r:add_input_filter(filter_name) -- Adds 'filter_name' as an input filter
</highlight>
<highlight language="lua">
r:module_info(module_name) -- Queries the server for information about a module
</highlight>
<highlight language="lua">
r:loaded_modules() -- Returns a list of modules loaded by httpd
</highlight>
<highlight language="lua">
r:runtime_dir_relative(filename) -- Compute the name of a run-time file (e.g., shared memory "file")
-- relative to the appropriate run-time directory.
</highlight>
<highlight language="lua">
r:server_info() -- Returns a table containing server information, such as
-- the name of the httpd executable file, mpm used etc.
</highlight>
<highlight language="lua">
r:set_document_root(file_path) -- Sets the document root for the request to file_path
</highlight>
<highlight language="lua">
r:add_version_component(component_string) -- Adds a component to the server banner.
</highlight>
<highlight language="lua">
r:set_context_info(prefix, docroot) -- Sets the context prefix and context document root for a request
</highlight>
<highlight language="lua">
r:os_escape_path(file_path) -- Converts an OS path to a URL in an OS dependant way
</highlight>
<highlight language="lua">
r:escape_logitem(string) -- Escapes a string for logging
</highlight>
<highlight language="lua">
r:strcmp_match(string, pattern) -- Checks if 'string' matches 'pattern' using strcmp_match (GLOBs).
-- fx. whether 'www.example.com' matches '*.example.com'
</highlight>
<highlight language="lua">
r:set_keepalive() -- Sets the keepalive status for a request. Returns true if possible, false otherwise.
</highlight>
<highlight language="lua">
r:make_etag() -- Constructs and returns the etag for the current request.
</highlight>
<highlight language="lua">
r:send_interim_response(clear) -- Sends an interim (1xx) response to the client.
-- if 'clear' is true, available headers will be sent and cleared.
</highlight>
<highlight language="lua">
r:custom_response(status_code, string) -- Construct and set a custom response for a given status code.
-- This works much like the ErrorDocument directive.
</highlight>
<highlight language="lua">
r:exists_config_define(string) -- Checks whether a configuration definition exists or not.
</highlight>
<highlight language="lua">
r:state_query(string) -- Queries the server for state information
</highlight>
<highlight language="lua">
r:stat(filename) -- Runs stat() on a file, and returns a table with file information
</highlight>
<highlight language="lua">
r:regex(string, pattern) -- Runs a regular expression match on a string, returning captures if matched.
</highlight>
<highlight language="lua">
r:sleep(number_of_seconds) -- Puts the script to sleep for a given number of seconds.
</highlight>
</dd>
</dl>

File diff suppressed because it is too large Load Diff

View File

@@ -18,8 +18,20 @@
#ifndef _LUA_APR_H_
#define _LUA_APR_H_
#include "scoreboard.h"
#include "http_main.h"
#include "ap_mpm.h"
#include "apr_md5.h"
#include "apr_sha1.h"
#include "apr_poll.h"
#include "apr.h"
#include "apr_tables.h"
#include "apr_base64.h"
AP_LUA_DECLARE(int) ap_lua_init(lua_State *L, apr_pool_t * p);
AP_LUA_DECLARE(apr_table_t*) ap_lua_check_apr_table(lua_State *L, int index);
AP_LUA_DECLARE(void) ap_lua_push_apr_table(lua_State *L, apr_table_t *t);
AP_LUA_DECLARE(int) ap_lua_load_httpd_functions(lua_State *L);
#endif /* !_LUA_APR_H_ */

View File

@@ -88,6 +88,7 @@ static void lua_open_callback(lua_State *L, apr_pool_t *p, void *ctx)
ap_lua_init(L, p);
ap_lua_load_apache2_lmodule(L);
ap_lua_load_request_lmodule(L, p);
ap_lua_load_httpd_functions(L);
ap_lua_load_config_lmodule(L);
}