iLua Server Module

This module implements a simple HTTP server based on Mongoose library.

Server library

server.create([port])
Create a new server object, optionally starting to listen to port. Otherwise, the port can be specified with server:option.
server:shutdown()
Destroys the server.
server:option(name[, value])
Set or retrieve an option. Returns the old option value, and replaces it with the new value if value is specified. List of available options can be found here.
server:route(path, func)
Requests with URI matching path regex will be handled by function func (expressions are checked in the order they were added). The function arguments are the connection object and the regex match (or a list of strings if the regex was created with re.LIST flag).
server.redirect(url[, code])
Create a function that will generate a redirect header to url, with status code (default is 302: Found, which is a temporary redirect).

Server connection object

server.connection extends the stream type, implementing the write operations. Note that status and headers must be sent before any write operations (status is sent before headers).

server.connection:sendstatus(code)
Send status code.
server.connection:sendheader(name, value)
Send HTTP header. Length header does not need to be sent as the connection will transfer the content in chunks.

RivSoft.net by Riv (riv@rivsoft.net) - All rights reserved