3 (c) 2009 Steven Barth <steven@midlink.org>
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
14 local cbi = require "luci.cbi"
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 srv = require "luci.lucid.http.server"
20 local coroutine = require "coroutine"
23 module "luci.lucid.http.handler.luci"
25 Luci = util.class(srv.Handler)
27 function Luci.__init__(self, name, prefix)
28 srv.Handler.__init__(self, name)
31 self.dsp_tree = dsp.createtree()
34 function Luci.handle_HEAD(self, ...)
35 local stat, head = self:handle_GET(...)
39 function Luci.handle_POST(self, ...)
40 return self:handle_GET(...)
43 function Luci.handle_GET(self, request, sourcein)
44 local r = http.Request(
49 local res, id, data1, data2 = true, 0, nil, nil
54 local x = coroutine.create(dsp.httpdispatch)
55 while not id or id < 3 do
56 res, id, data1, data2 = coroutine.resume(x, r, self.prefix, self.dsp_tree)
60 headers["Content-Type"] = "text/plain"
61 return status, headers, ltn12.source.string(id)
67 if not headers[data1] then
68 headers[data1] = data2
69 elseif type(headers[data1]) ~= "table" then
70 headers[data1] = {headers[data1], data2}
72 headers[data1][#headers[data1]+1] = data2
78 while (coroutine.resume(x)) do end
79 return status, headers, srv.IOResource(data1, data2)
83 local res, id, data = coroutine.resume(x)
86 elseif not id or not active then
90 while (coroutine.resume(x)) do end
97 return status, headers, iter