libs/web: don't send Status: 500 in error500() if header is already sent
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 9 Feb 2009 13:17:26 +0000 (13:17 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 9 Feb 2009 13:17:26 +0000 (13:17 +0000)
modules/admin-core: include template header only once

libs/web/luasrc/dispatcher.lua
modules/admin-core/luasrc/view/header.htm

index 5110209aacb21e0ab6781d61b49b016ebe7bce1e..538017dc75cda5af8be6e2825425e152e37faf18 100644 (file)
@@ -74,12 +74,14 @@ end
 -- @param message      Custom error message (optional)#
 -- @return                     false
 function error500(message)
-       luci.http.status(500, "Internal Server Error")
-
-       require("luci.template")
-       if not luci.util.copcall(luci.template.render, "error500", {message=message}) then
-               luci.http.prepare_content("text/plain")
-               luci.http.write(message)
+       if not context.template_header_sent then
+               luci.http.status(500, "Internal Server Error")
+       else
+               require("luci.template")
+               if not luci.util.copcall(luci.template.render, "error500", {message=message}) then
+                       luci.http.prepare_content("text/plain")
+                       luci.http.write(message)
+               end
        end
        return false
 end
@@ -589,7 +591,7 @@ end
 
 
 local function _call(self, ...)
-       if #self.argv > 0 then 
+       if #self.argv > 0 then
                return getfenv()[self.name](unpack(self.argv), ...)
        else
                return getfenv()[self.name](...)
index 6625e46b03299e1d6e7fcf1fa5dbad61eed259c9..77018b117336b8136786a315a3f473c37140fdc1 100644 (file)
@@ -12,4 +12,10 @@ You may obtain a copy of the License at
 $Id$
 
 -%>
-<% include("themes/" .. theme .. "/header") %>
\ No newline at end of file
+
+<%
+       if not luci.dispatcher.context.template_header_sent then
+               include("themes/" .. theme .. "/header")
+               luci.dispatcher.context.template_header_sent = true
+       end
+%>