changeset 3139:03cda95ae97a

mod_pastebin: Prevent header table form being mutated default_headers was mutated, probably by mod_http_errors and ended up with multiple content-type entries, which led to issues in browsers which would sometimes treat the paste as html
author Kim Alvefur <zash@zash.se>
date Sat, 23 Jun 2018 16:37:15 +0200
parents 9817e45a79e6
children 11087a72990b
files mod_pastebin/mod_pastebin.lua
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_pastebin/mod_pastebin.lua	Fri Jun 22 15:19:55 2018 +0200
+++ b/mod_pastebin/mod_pastebin.lua	Sat Jun 23 16:37:15 2018 +0200
@@ -51,7 +51,6 @@
 trigger_string = (trigger_string and trigger_string .. " ");
 
 local pastes = {};
-local default_headers = { ["Content-Type"] = "text/plain; charset=utf-8" };
 
 local xmlns_xhtmlim = "http://jabber.org/protocol/xhtml-im";
 local xmlns_xhtml = "http://www.w3.org/1999/xhtml";
@@ -67,14 +66,20 @@
 end
 
 function handle_request(event, pasteid)
-	if not pasteid or not pastes[pasteid] then
-		event.response.headers = default_headers;
-		return event.response:send("Invalid paste id, perhaps it expired?");
+	event.response.headers.content_type = "text/plain; charset=utf-8";
+
+	if not pasteid then
+		return "Invalid paste id, perhaps it expired?";
 	end
 
 	--module:log("debug", "Received request, replying: %s", pastes[pasteid].text);
+	local paste = pastes[pasteid];
 
-	return pastes[pasteid];
+	if not paste then
+		return "Invalid paste id, perhaps it expired?";
+	end
+
+	return paste.body;
 end
 
 local function replace_tag(s, replacement)