Changeset

8362:c7d6c2558a24

net.http.server: Include response object in most http-error events
author Kim Alvefur <zash@zash.se>
date Fri, 27 Oct 2017 14:08:28 +0200
parents 8361:6af950b834a6
children 8363:e2460edc2a2f
files net/http/server.lua
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/net/http/server.lua	Sun Oct 29 00:07:45 2017 +0200
+++ b/net/http/server.lua	Fri Oct 27 14:08:28 2017 +0200
@@ -229,7 +229,7 @@
 
 	if err then
 		response.status_code = err_code;
-		response:send(events.fire_event("http-error", { code = err_code, message = err }));
+		response:send(events.fire_event("http-error", { code = err_code, message = err, response = response }));
 		return;
 	end
 
@@ -244,7 +244,8 @@
 			if result_type == "number" then
 				response.status_code = result;
 				if result >= 400 then
-					body = events.fire_event("http-error", { code = result });
+					payload.code = result;
+					body = events.fire_event("http-error", payload);
 				end
 			elseif result_type == "string" then
 				body = result;
@@ -266,7 +267,8 @@
 
 	-- if handler not called, return 404
 	response.status_code = 404;
-	response:send(events.fire_event("http-error", { code = 404 }));
+	payload.code = 404;
+	response:send(events.fire_event("http-error", payload));
 end
 local function prepare_header(response)
 	local status_line = "HTTP/"..response.request.httpversion.." "..(response.status or codes[response.status_code]);