mod_http_errors: Add way to reuse the error page template

module:fire_event("http-message", {title = "hello"; message = "world"})

Goal is to enable consistent messages from Prosody. Not necessarily
error messages, but warnings or just notices.

This does cause some drift in the purpose of mod_http_errors, but that's
okay.
This commit is contained in:
Kim Alvefur 2021-02-21 06:13:19 +01:00
parent 699e27da56
commit 6d29fa653c

View file

@ -64,6 +64,13 @@ module:hook_object_event(server, "http-error", function (event)
return get_page(event.code, (show_private and event.private_message) or event.message or (event.error and event.error.text));
end);
module:hook("http-message", function (event)
if event.response then
event.response.headers.content_type = "text/html; charset=utf-8";
end
return render(html, event);
end);
module:hook_object_event(server, "http-error", function (event)
local request, response = event.request, event.response;
if request and response and request.path == "/" and response.status_code == 404 then