1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2018 Jo-Philipp Wich <jo@mein.io>
3 -- Licensed to the public under the Apache License 2.0.
5 local util = require "luci.util"
6 local coroutine = require "coroutine"
7 local table = require "table"
8 local lhttp = require "lucihttp"
10 local L, table, ipairs, pairs, type, error = _G.L, table, ipairs, pairs, type, error
14 HTTP_MAX_CONTENT = 1024*100 -- 100 kB maximum content size
21 return L.http:content()
24 function formvalue(name, noparse)
25 return L.http:formvalue(name, noparse)
28 function formvaluetable(prefix)
29 return L.http:formvaluetable(prefix)
32 function getcookie(name)
33 return L.http:getcookie(name)
36 -- or the environment table itself.
38 return L.http:getenv(name)
41 function setfilehandler(callback)
42 return L.http:setfilehandler(callback)
45 function header(key, value)
46 L.http:header(key, value)
49 function prepare_content(mime)
50 L.http:prepare_content(mime)
57 function status(code, message)
58 L.http:status(code, message)
61 -- This function is as a valid LTN12 sink.
62 -- If the content chunk is nil this function will automatically invoke close.
63 function write(content, src_err)
68 return L.print(content)
71 function splice(fd, size)
72 coroutine.yield(6, fd, size)
75 function redirect(url)
79 function build_querystring(q)
80 local s, n, k, v = {}, 1, nil, nil
82 for k, v in pairs(q) do
83 s[n+0] = (n == 1) and "?" or "&"
84 s[n+1] = util.urlencode(k)
86 s[n+3] = util.urlencode(v)
90 return table.concat(s, "")
93 urldecode = util.urldecode
95 urlencode = util.urlencode
97 function write_json(x)
101 -- separated by "&". Tables are encoded as parameters with multiple values by
102 -- repeating the parameter name with each value.
103 function urlencode_params(tbl)
106 for k, v in pairs(tbl) do
107 if type(v) == "table" then
109 for i, v2 in ipairs(v) do
115 enc[n+0] = lhttp.urlencode(k)
117 enc[n+2] = lhttp.urlencode(v2)
126 enc[n+0] = lhttp.urlencode(k)
128 enc[n+2] = lhttp.urlencode(v)
133 return table.concat(enc, "")
138 formvalue = function(self, ...) return formvalue(...) end;
139 formvaluetable = function(self, ...) return formvaluetable(...) end;
140 content = function(self, ...) return content(...) end;
141 getcookie = function(self, ...) return getcookie(...) end;
142 setfilehandler = function(self, ...) return setfilehandler(...) end;
143 message = L.http.message