Diff

mod_rest/mod_rest.lua @ 3816:8473fd2d09c1

mod_rest: Default to replying with same type as request If you send JSON then you get JSON back unless you say something different with the Accept header.
author Kim Alvefur <zash@zash.se>
date Wed, 01 Jan 2020 16:40:10 +0100
parent 3815:1a0a612d36bc
child 3821:11272a3233ce
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Wed Jan 01 16:37:18 2020 +0100
+++ b/mod_rest/mod_rest.lua	Wed Jan 01 16:40:10 2020 +0100
@@ -102,7 +102,7 @@
 		["xml:lang"] = payload.attr["xml:lang"],
 	};
 	module:log("debug", "Received[rest]: %s", payload:top_tag());
-	local send_type = decide_type(request.headers.accept)
+	local send_type = decide_type((request.headers.accept or "") ..",".. request.headers.content_type)
 	if payload.name == "iq" then
 		if payload.attr.type ~= "get" and payload.attr.type ~= "set" then
 			return errors.new({ code = 422, text = "'iq' stanza must be of type 'get' or 'set'" });