libs/sgi-cgi: Workaround for broken CGI implementation of Busybox HTTPd
[project/luci.git] / libs / sgi-cgi / luasrc / sgi / cgi.lua
index 5555e4a..0d5ba6f 100644 (file)
@@ -24,7 +24,7 @@ limitations under the License.
 
 ]]--
 module("luci.sgi.cgi", package.seeall)
-require("ltn12")
+local ltn12 = require("luci.ltn12")
 require("luci.http")
 require("luci.sys")
 require("luci.dispatcher")
@@ -37,6 +37,7 @@ function run()
        )
        
        local x = coroutine.create(luci.dispatcher.httpdispatch)
+       local hcache = ""
        
        while coroutine.status(x) ~= "dead" do
                local res, id, data1, data2 = coroutine.resume(x, r)
@@ -49,11 +50,12 @@ function run()
                end
 
                if id == 1 then
-                       io.write("Status: " .. tostring(data1) .. " " .. data2 .. "\n")
+                       io.write("Status: " .. tostring(data1) .. " " .. data2 .. "\r\n")
                elseif id == 2 then
-                       io.write(data1 .. ": " .. data2 .. "\n")
+                       hcache = hcache .. data1 .. ": " .. data2 .. "\r\n"
                elseif id == 3 then
-                       io.write("\n")
+                       io.write(hcache)
+                       io.write("\r\n")
                elseif id == 4 then
                        io.write(data1)
                end