2 LuCI - Server Gateway Interface for the uHTTPd server
4 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
23 require "luci.dispatcher"
26 function handle_request(env)
29 CONTENT_LENGTH = env.CONTENT_LENGTH,
30 CONTENT_TYPE = env.CONTENT_TYPE,
31 REQUEST_METHOD = env.REQUEST_METHOD,
32 REQUEST_URI = env.REQUEST_URI,
33 PATH_INFO = env.PATH_INFO,
34 SCRIPT_NAME = env.SCRIPT_NAME:gsub("/+$", ""),
35 SCRIPT_FILENAME = env.SCRIPT_NAME,
36 SERVER_PROTOCOL = env.SERVER_PROTOCOL,
37 QUERY_STRING = env.QUERY_STRING
41 for k, v in pairs(env.headers) do
42 k = k:upper():gsub("%-", "_")
43 renv["HTTP_" .. k] = v
46 local len = tonumber(env.CONTENT_LENGTH) or 0
49 local rlen, rbuf = uhttpd.recv(4096)
58 local send = uhttpd.send
60 local req = luci.http.Request(
61 renv, recv, luci.ltn12.sink.file(io.stderr)
65 local x = coroutine.create(luci.dispatcher.httpdispatch)
69 while coroutine.status(x) ~= "dead" do
70 local res, id, data1, data2 = coroutine.resume(x, req)
73 send("Status: 500 Internal Server Error\r\n")
74 send("Content-Type: text/plain\r\n\r\n")
89 for k, v in pairs(hcache) do
97 send(tostring(data1 or ""))
101 data1:copyz(nixio.stdout, data2)