docs

function reference

add_vhost (vhost-table)
Input
  1. vhost-table - a hashtable that describes the new vhost
Output
  1. 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
  1. vhost-object - a valid vhost
  2. path - the path to match (end it with * to match everything under it)
  3. mode - 0 runs the callback before the request is started, 99 runs it after it finishes
  4. callback - a callback that takes a single request object and returns nil if passthrough or true if it ends the process chain
Output
  1. No return
redirect_log (log path, debug mask)
Input
  1. log path - a file path for where to redirect stdout & stderr (optional)
  2. debug mask - a string that represents a mask for what debug output to show (optional) valid values are "0", "ffffffff"
Output
  1. No return
proxy (request-object, uri)

proxies a request for uri to client

Input
  1. request-object
  2. uri is in the form of "http(s)://host(:port)/request"
Output
  1. No return
cgi (request-object, executable path, htdocs / root dir, file path)

executes cgi program and pipes the output to client

Input
  1. request-object
Output
  1. 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
  1. request-object
  2. a fcgi group object created by the create_fcgi function
Output
  1. No return
create_fcgi (uri)

createst a fcgi group

Input
  1. uri in the form tcp://host(:port)/
Output
  1. a fcgi group object
respond (request-object, http status code, optional body)

returns a raw message to client

Input
  1. request-object
Output
  1. No return
Example
respond (req, 403, "don't look")
remote_address (request-object)
Input
  1. request-object
Output
  1. ip address
  2. port number
add_header (request-object, name, value)

adds header to response

Input
  1. request-object
Output
  1. No return
shutdown (request-object)

close http connection without any response

Input
  1. request-object
Output
  1. No return
set_content_type (request-object, content type string)

sets content type returned

Input
  1. request-object
  2. content type string
Output
  1. 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
  1. path to log file
Output
  1. write to log function
Example
logfunc = create_log ("log.txt")
logfunc ("hello")
nil_log ()

create a virtual log that doesn't write anywhere

Input
  1. request-object
Output
  1. No return
parse_path (request-object)
Input
  1. request-object
Output
  1. returns path, query string, method, http version
parse_headers (request-object)

returns request headers

Input
  1. request-object
Output
  1. 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
  1. request-object - a valid request object
  2. path - path to the file requested relative to htdocs of the vhost
  3. index_files - a list of index files or a list of tables of index files
Output
  1. 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