diff mod_pubsub_github/mod_pubsub_github.lua @ 3508:a98a3922bc01

mod_pubsub_github: Send sensible status codes
author Kim Alvefur <zash@zash.se>
date Sun, 31 Mar 2019 16:05:24 +0200
parents d4207ab8ccc1
children 94414cadfcaa
line wrap: on
line diff
--- a/mod_pubsub_github/mod_pubsub_github.lua	Sun Mar 31 04:49:56 2019 +0200
+++ b/mod_pubsub_github/mod_pubsub_github.lua	Sun Mar 31 16:05:24 2019 +0200
@@ -9,12 +9,13 @@
 local secret = module:get_option("github_secret");
 
 function handle_POST(event)
-	local request = event.request;
+	local request, response = event.request, event.response;
 	if secret and ("sha1=" .. hmac_sha1(secret, request.body, true)) ~= request.headers.x_hub_signature then
 		return 401;
 	end
 	local data = json.decode(request.body);
 	if not data then
+		response.status_code = 400;
 		return "Invalid JSON. From you of all people...";
 	end
 
@@ -34,6 +35,7 @@
 	end
 
 	module:log("debug", "Handled POST: \n%s\n", tostring(request.body));
+	response.status_code = 202;
 	return "Thank you Github!";
 end