Remove overload protection from SDK httpd
[project/luci.git] / libs / httpd / luasrc / httpd / handler / luci.lua
index 4a83de1..8ccf7c8 100644 (file)
@@ -18,13 +18,16 @@ module("luci.httpd.handler.luci", package.seeall)
 require("luci.dispatcher")
 require("luci.http")
 require("luci.http.protocol.date")
-require("ltn12")
+local ltn12 = require("luci.ltn12")
 
 Luci = luci.util.class(luci.httpd.module.Handler)
 Response = luci.httpd.module.Response
 
-function Luci.__init__(self)
+function Luci.__init__(self, limit)
        luci.httpd.module.Handler.__init__(self)
+       self.limit = limit or 5
+       self.running = {}
+       setmetatable(self.running, {__mode = "k"})
 end
 
 function Luci.handle_head(self, ...)
@@ -46,6 +49,7 @@ function Luci.handle_get(self, request, sourcein, sinkerr)
        local res, id, data1, data2 = true, 0, nil, nil
        local headers = {}
        local status = 200
+       local active = true
 
        local x = coroutine.create(luci.dispatcher.httpdispatch)
        while not id or id < 3 do
@@ -71,17 +75,22 @@ function Luci.handle_get(self, request, sourcein, sinkerr)
                local res, id, data = coroutine.resume(x)
                if not res then
                        return nil, id
-               elseif not id then
+               elseif not id or not active then
                        return true
                elseif id == 5 then
+                       active = false
+
+                       while (coroutine.resume(x)) do
+                       end
+
                        return nil
-               else
+               elseif id == 4 then
                        return data
                end
+               if coroutine.status(x) == "dead" then
+                       return nil
+               end
        end
 
-       headers["Expires"] = luci.http.protocol.date.to_http( os.time() )
-       headers["Date"]    = headers["Expires"]
-
        return Response(status, headers), iter
 end