From b5026e65c0334f9d8afddb0a3ca1797ef2baff5c Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 9 Feb 2009 13:17:26 +0000 Subject: [PATCH] libs/web: don't send Status: 500 in error500() if header is already sent modules/admin-core: include template header only once --- libs/web/luasrc/dispatcher.lua | 16 +++++++++------- modules/admin-core/luasrc/view/header.htm | 8 +++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua index 5110209aa..538017dc7 100644 --- a/libs/web/luasrc/dispatcher.lua +++ b/libs/web/luasrc/dispatcher.lua @@ -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](...) diff --git a/modules/admin-core/luasrc/view/header.htm b/modules/admin-core/luasrc/view/header.htm index 6625e46b0..77018b117 100644 --- a/modules/admin-core/luasrc/view/header.htm +++ b/modules/admin-core/luasrc/view/header.htm @@ -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 +%> -- 2.25.1