function reference
add_vhost (vhost-table)
Input
- vhost-table - a hashtable that describes the new vhost
Output
- returns a vhost-object to be used in other functions
map (vhost-object, path, mode, callback)
adds a map callback, processed in the order they are added
Input
- vhost-object - a valid vhost
- path - the path to match (end it with * to match everything under it)
- mode - 0 runs the callback before the request is started, 99 runs it after it finishes
- callback - a callback that takes a single request object and returns nil if passthrough or true if it ends the process chain
Output
- No return
redirect_log (log path, debug mask)
Input
- log path - a file path for where to redirect stdout & stderr (optional)
- debug mask - a string that represents a mask for what debug output to show (optional) valid values are "0", "ffffffff"
Output
- No return
proxy (request-object, uri)
proxies a request for uri to client
Input
- request-object
- uri is in the form of "http(s)://host(:port)/request"
Output
- No return
cgi (request-object, executable path, htdocs / root dir, file path)
executes cgi program and pipes the output to client
Input
- request-object
Output
- No return
fastcgi (request-object, fcgi-group, htdocs / root dir, file path)
proxies a fastcgi request to a fpm socket and pipes the output to client
Input
- request-object
- a fcgi group object created by the create_fcgi function
Output
- No return
create_fcgi (uri)
createst a fcgi group
Input
- uri in the form tcp://host(:port)/
Output
- a fcgi group object
respond (request-object, http status code, optional body)
returns a raw message to client
Input
- request-object
Output
- No return
Example
respond (req, 403, "don't look")
remote_address (request-object)
Input
- request-object
Output
- ip address
- port number
add_header (request-object, name, value)
adds header to response
Input
- request-object
Output
- No return
shutdown (request-object)
close http connection without any response
Input
- request-object
Output
- No return
set_content_type (request-object, content type string)
sets content type returned
Input
- request-object
- content type string
Output
- No return
Example
set_content_type (req, "text/html")
create_log (path)
it creates a log and returns a function that write to it
Input
- path to log file
Output
- write to log function
Example
logfunc = create_log ("log.txt")
logfunc ("hello")
nil_log ()
create a virtual log that doesn't write anywhere
Input
- request-object
Output
- No return
parse_path (request-object)
Input
- request-object
Output
- returns path, query string, method, http version
parse_headers (request-object)
returns request headers
Input
- request-object
Output
- returns headers as a lua hashtable
set_path (request-object, path, index_files ... index_file(n+1))
looks up the vfs cache and sets (path) as the current file to serve index file(s) is an ordered list of files to look for if path is a directory
Input
- request-object - a valid request object
- path - path to the file requested relative to htdocs of the vhost
- index_files - a list of index files or a list of tables of index files
Output
- if path points to a file returns: dirname(), basename(), last file extension, path_info (if present) if path points to a directory: directory path, nil, nil, path_info, and location is present only if a redirect would be issued (for more info check server option directory_no_redirect)
Example
expl: /var/www/htdocs/index.php/hey
dir path: /var/www/htdocs/
file name: index.php
ext: php
path info: /hey