From c6540b14f9fbd99a42d00ac616bc48ff0b146690 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 21 Sep 2018 21:19:41 +0200 Subject: 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 | 2 +- plugins/mod_http.lua | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/net/http/server.lua b/net/http/server.lua index 877c7f17..a982d53f 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -233,7 +233,7 @@ function handle_request(conn, request, finish_cb) 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); diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua index 28d5d2d4..bd94de40 100644 --- a/plugins/mod_http.lua +++ b/plugins/mod_http.lua @@ -172,7 +172,13 @@ module:wrap_object_event(server._events, false, function (handlers, event_name, -- 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", { -- cgit v1.2.3