X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fhttpd%2Fluasrc%2Fhttpd%2Fhandler%2Fluci.lua;h=4a83de1a4c93afec35d327d7f61bdd346a01d34d;hp=35f832d4531c64f977c09fcda834a816668f3283;hb=e08b97565f2a2dfeb482be0f061bfefa93d32556;hpb=7a4aa85dd64f72b9edcbf9310d0d95e59960d84e diff --git a/libs/httpd/luasrc/httpd/handler/luci.lua b/libs/httpd/luasrc/httpd/handler/luci.lua index 35f832d45..4a83de1a4 100644 --- a/libs/httpd/luasrc/httpd/handler/luci.lua +++ b/libs/httpd/luasrc/httpd/handler/luci.lua @@ -1,6 +1,23 @@ +--[[ + +HTTP server implementation for LuCI - luci handler +(c) 2008 Steven Barth + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ + +]]-- + module("luci.httpd.handler.luci", package.seeall) + require("luci.dispatcher") require("luci.http") +require("luci.http.protocol.date") require("ltn12") Luci = luci.util.class(luci.httpd.module.Handler) @@ -19,37 +36,37 @@ function Luci.handle_post(self, ...) return self:handle_get(...) end -function Luci.handle_get(self, request, sourcein, sinkerr) +function Luci.handle_get(self, request, sourcein, sinkerr) local r = luci.http.Request( request.env, sourcein, sinkerr ) - + local res, id, data1, data2 = true, 0, nil, nil local headers = {} local status = 200 - + local x = coroutine.create(luci.dispatcher.httpdispatch) while not id or id < 3 do coroutine.yield() - + res, id, data1, data2 = coroutine.resume(x, r) - + if not res then status = 500 headers["Content-Type"] = "text/plain" local err = {id} - return status, headers, function() local x = table.remove(err) return x end + return Response( status, headers ), function() return table.remove(err) end end - + if id == 1 then status = data1 elseif id == 2 then headers[data1] = data2 end end - + local function iter() local res, id, data = coroutine.resume(x) if not res then @@ -62,6 +79,9 @@ function Luci.handle_get(self, request, sourcein, sinkerr) return data end end - + + headers["Expires"] = luci.http.protocol.date.to_http( os.time() ) + headers["Date"] = headers["Expires"] + return Response(status, headers), iter -end \ No newline at end of file +end