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 dsp = require "luci.dispatcher"
15 local util = require "luci.util"
16 local http = require "luci.http"
17 local ltn12 = require "luci.ltn12"
18 local srv = require "luci.lucid.http.server"
19 local coroutine = require "coroutine"
22 module "luci.lucid.http.handler.luci"
24 Luci = util.class(srv.Handler)
26 function Luci.__init__(self, name, prefix)
27 srv.Handler.__init__(self, name)
31 function Luci.handle_HEAD(self, ...)
32 local stat, head = self:handle_GET(...)
36 function Luci.handle_POST(self, ...)
37 return self:handle_GET(...)
40 function Luci.handle_GET(self, request, sourcein)
41 local r = http.Request(
46 local res, id, data1, data2 = true, 0, nil, nil
51 local x = coroutine.create(dsp.httpdispatch)
52 while not id or id < 3 do
53 res, id, data1, data2 = coroutine.resume(x, r, self.prefix)
57 headers["Content-Type"] = "text/plain"
58 return status, headers, ltn12.source.string(id)
64 if not headers[data1] then
65 headers[data1] = data2
66 elseif type(headers[data1]) ~= "table" then
67 headers[data1] = {headers[data1], data2}
69 headers[data1][#headers[data1]+1] = data2
75 while (coroutine.resume(x)) do end
76 return status, headers, srv.IOResource(data1, data2)
80 local res, id, data = coroutine.resume(x)
83 elseif not id or not active then
87 while (coroutine.resume(x)) do end
94 return status, headers, iter