3 HTTP server implementation for LuCI - luci handler
4 (c) 2008 Steven Barth <steven@midlink.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
15 local dsp = require "luci.dispatcher"
16 local util = require "luci.util"
17 local http = require "luci.http"
18 local ltn12 = require "luci.ltn12"
19 local mod = require "luci.ttpd.module"
20 local table = require "table"
21 local coroutine = require "coroutine"
23 module "luci.ttpd.handler.luci"
25 Luci = util.class(mod.Handler)
26 Response = mod.Response
28 function Luci.__init__(self, limit)
29 mod.Handler.__init__(self)
32 function Luci.handle_head(self, ...)
33 return (self:handle_get(...))
36 function Luci.handle_post(self, ...)
37 return self:handle_get(...)
40 function Luci.handle_get(self, request, sourcein, sinkerr)
41 local r = http.Request(
47 local res, id, data1, data2 = true, 0, nil, nil
52 local x = coroutine.create(dsp.httpdispatch)
53 while not id or id < 3 do
54 res, id, data1, data2 = coroutine.resume(x, r)
58 headers["Content-Type"] = "text/plain"
60 return Response( status, headers ), function() return table.remove(err) end
66 headers[data1] = data2
71 local res, id, data = coroutine.resume(x)
74 elseif not id or not active then
79 while (coroutine.resume(x)) do
86 if coroutine.status(x) == "dead" then
91 return Response(status, headers), iter