Changeset

9335:2dc7490899ae

net.http.server: Move handling of hosts to mod_http Now an event like `GET /path` is fired at first, and mod\_http dispatches the old `GET host/path` events.
author Kim Alvefur <zash@zash.se>
date Fri, 21 Sep 2018 21:19:41 +0200
parents 9334:a86736e0163c
children 9336:9e8d7d461c7d
files net/http/server.lua plugins/mod_http.lua
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/net/http/server.lua	Fri Sep 21 15:34:45 2018 +0200
+++ b/net/http/server.lua	Fri Sep 21 21:19:41 2018 +0200
@@ -233,7 +233,7 @@
 		return;
 	end
 
-	local event = request.method.." "..host..request.path:match("[^?]*");
+	local event = request.method.." "..request.path:match("[^?]*");
 	local payload = { request = request, response = response };
 	log("debug", "Firing event: %s", event);
 	local result = events.fire_event(event, payload);
--- a/plugins/mod_http.lua	Fri Sep 21 15:34:45 2018 +0200
+++ b/plugins/mod_http.lua	Fri Sep 21 21:19:41 2018 +0200
@@ -172,7 +172,13 @@
 		-- Not included in eg http-error events
 		request.ip = get_ip_from_request(request);
 	end
-	return handlers(event_name, event_data);
+	local ret = handlers(event_name, event_data);
+	if ret ~= nil then
+		return ret;
+	end
+	local host = (request.headers.host or ""):match("[^:]+");
+	local host_event = request.method.." "..host..request.path:match("[^?]*");
+	return handlers(host_event, event_data);
 end);
 
 module:provides("net", {