Changeset

11389:29e7ed75ed3f

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.
author Kim Alvefur <zash@zash.se>
date Sun, 21 Feb 2021 06:13:19 +0100
parents 11388:60a61c509d87
children 11390:226fd5d3a295
files plugins/mod_http_errors.lua
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http_errors.lua	Thu Feb 18 14:55:38 2021 +0100
+++ b/plugins/mod_http_errors.lua	Sun Feb 21 06:13:19 2021 +0100
@@ -64,6 +64,13 @@
 	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