aboutsummaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-09-23 18:59:04 +0200
committerKim Alvefur <zash@zash.se>2018-09-23 18:59:04 +0200
commit95eac7d4c6f95e84274d9a547c77aa6c1418100a (patch)
tree3618f8ecc03bcb74719869ceb1cad2a79fbda379 /net/http
parenteab76309e8547d51cdd1e0c38e7222ade4c0848d (diff)
downloadprosody-95eac7d4c6f95e84274d9a547c77aa6c1418100a.tar.gz
prosody-95eac7d4c6f95e84274d9a547c77aa6c1418100a.zip
net.http.server: Delay host checks until after host-less event
This allows handling events without any hosts enabled.
Diffstat (limited to 'net/http')
-rw-r--r--net/http/server.lua27
1 files changed, 18 insertions, 9 deletions
diff --git a/net/http/server.lua b/net/http/server.lua
index 5b42208c..b73f3385 100644
--- a/net/http/server.lua
+++ b/net/http/server.lua
@@ -217,14 +217,6 @@ function handle_request(conn, request, finish_cb)
local err_code, err;
if not request.path then
err_code, err = 400, "Invalid path";
- elseif not hosts[host] then
- if hosts[default_host] then
- host = default_host;
- elseif host then
- err_code, err = 404, "Unknown host: "..host;
- else
- err_code, err = 400, "Missing or invalid 'Host' header";
- end
end
if err then
@@ -234,11 +226,28 @@ function handle_request(conn, request, finish_cb)
end
local global_event = request.method.." "..request.path:match("[^?]*");
- local host_event = request.method.." "..host..request.path:match("[^?]*");
+
local payload = { request = request, response = response };
log("debug", "Firing event: %s", global_event);
local result = events.fire_event(global_event, payload);
if result == nil then
+ if not hosts[host] then
+ if hosts[default_host] then
+ host = default_host;
+ elseif host then
+ err_code, err = 404, "Unknown host: "..host;
+ else
+ err_code, err = 400, "Missing or invalid 'Host' header";
+ end
+ end
+ local host_event = request.method.." "..host..request.path:match("[^?]*");
+
+ if err then
+ response.status_code = err_code;
+ response:send(events.fire_event("http-error", { code = err_code, message = err, response = response }));
+ return;
+ end
+
log("debug", "Firing event: %s", host_event);
result = events.fire_event(host_event, payload);
end