This is a Lua plugin for scipting purposes for the Monkey HTTP daemon.
You can execute a Lua script and return the response. You get access to few of monkey's internals in the lua environment.
- Latest Monkey HTTP daemon git master.
- Lua 5.2
cd monkey
git clone https://github.com/diadara/monkey_lua.git plugins/lua
./configure
make
# Edit conf/plugins.load and uncomment line with monkey-lua.so
# Edit conf/plugins/lua.conf
# put your scripts in htdocs
./bin/monkey
The plugin exposes a table mk
through which you can get the request
object and also set the response.
mk.print takes a string and prints it one the response body.
config table contains information about monkey server and the current configuration. This table consists of-
This table consists of 3 boolean fields TCP_FASTOPEN, SO_REUSEPORT, TCP_AUTOCORKING.
Monkey servers current worker capacity.
Number of running workers.
Maximum load that can be handled by the server currently.
Boolean indicating whether manual_tcp_cork.
Boolean indicating whether fdt enabled.
Boolean indicating whether monkey running in daemon mode.
Boolean indicating whether seteuid.
String indicating the current scheduler algorithm.
Current server configuration.
Current server listen address.
Current server address.
Current server software string.
Username under which server is running.
current user directory.
PID file path
Server configuration file.
Mimetypes configuration file.
Plugin load configuration file.
Sites configuration directory
Plugin configuration directory
Current transport (http/https).
Current transport layer.
Request table consists of following items:
Server software string.
Document root for the current request
Server name for the current request.
Current server address.
Current server port.
Script file name for the current request.
Current request method.
client address.
client port.
Request url for the current request.
query string
POST
or PUT
data.
Table with the http headers from the current request.
Function which parses the query string and returns two tables one with keys as the query string variable and value as it's value and other with key and other with query string variable as the key and value as an array of variable values.
t1, t2 = parseargs()
Function which parses the post data and returns two tables
t1, t2 = parsedata()
Response table consists of following items:
Set this variable to current request response status code. Default value set to 200.
Set http headers with this table
headers["Content-type"] = "text/json"
The cookie table consists of following items.
The function returns a table of cookies the client has sent.
The function takes a table as argument and sets the cookie accordingly.
cookies.set_cookie{name="name", value="nithin", httponly = true, secure=true, domain="nithinsaji.in", expiry=os.time()+60*60*8}