x.http - Web Server Hooks

#Firmware/v290
The web server hooks allow some simple HTML custom pages to be returned from Lua.

x.http.admin = function(t)
x.http.admin.onget
x.http.admin.onpost
x.http.admin.onhead

Called whenever the “/ext/admin/” region of the ip.buffer web-server is referenced.

x.http.user = function(t)
x.http.user.onget
x.http.user.onpost
x.http.user.onhead

Called whenever the “/ext/” or “/ext/public/” regions of the ip.buffer web-server is
referenced.

HTTP Hook Table t

Value Type Description
t.admin integer 0/1 - whether user or admin
t.filename string Filename
t.method string 'HEAD', 'GET', 'POST'
t.path string
t.queryuri string
t.uri string
t.client string IP address
t.scheme string 'http://' or 'https://'
t.relroot string prefix to use for URIs
t.headers table (list of [index]=values)
t.query table list of URL query values
t.cgi table list of CGI post parameters
t.post table list of multipart/mime post parameters

HTTP Hook Return Values

There are several different formats for return values from the hook function:

Type(s) Description
integer HTTP Response code, e.g. 404
string Plain HTML. If the string begins with <html> the ip.buffer header and footers are not applied. Otherwise, the text should conform to the same rules as the internal ip.buffer pages.
string, string Content with Content-Type. e.g. 'Hello!', 'plain/text' - this allows returning of images and other content.
table Discrete control over the response and HTTP headers. See #Table Return Value

Table Return Value

Index Type Description
.response integer HTTP response code
.headers table table of extra HTTP headers
.content string e.g. content='text/plain'
.body string the main body of response
.ipbuffer boolean set to true to add headers & footers