1 -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
7 require "luci.dispatcher"
10 function handle_request(env)
13 CONTENT_LENGTH = env.CONTENT_LENGTH,
14 CONTENT_TYPE = env.CONTENT_TYPE,
15 REQUEST_METHOD = env.REQUEST_METHOD,
16 REQUEST_URI = env.REQUEST_URI,
17 PATH_INFO = env.PATH_INFO,
18 SCRIPT_NAME = env.SCRIPT_NAME:gsub("/+$", ""),
19 SCRIPT_FILENAME = env.SCRIPT_NAME,
20 SERVER_PROTOCOL = env.SERVER_PROTOCOL,
21 QUERY_STRING = env.QUERY_STRING
25 for k, v in pairs(env.headers) do
26 k = k:upper():gsub("%-", "_")
27 renv["HTTP_" .. k] = v
30 local len = tonumber(env.CONTENT_LENGTH) or 0
33 local rlen, rbuf = uhttpd.recv(4096)
42 local send = uhttpd.send
44 local req = luci.http.Request(
45 renv, recv, luci.ltn12.sink.file(io.stderr)
49 local x = coroutine.create(luci.dispatcher.httpdispatch)
53 while coroutine.status(x) ~= "dead" do
54 local res, id, data1, data2 = coroutine.resume(x, req)
57 send("Status: 500 Internal Server Error\r\n")
58 send("Content-Type: text/plain\r\n\r\n")
73 for k, v in pairs(hcache) do
81 send(tostring(data1 or ""))
85 data1:copyz(nixio.stdout, data2)