net.http.server: Move handling of hosts to mod_http
authorKim Alvefur <zash@zash.se>
Fri, 21 Sep 2018 21:19:41 +0200
changeset 9338 2dc7490899ae
parent 9337 a86736e0163c
child 9339 9e8d7d461c7d
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.
net/http/server.lua
plugins/mod_http.lua
--- 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", {