Comparison

net/http/server.lua @ 10324:3f4c25425589

net.http.server: Re-fire unhandled HEAD requsts as GET events (fixes #1447) BC: This overloads the GET event. Previous commit ensures HEAD requests are sent without a body.
author Kim Alvefur <zash@zash.se>
date Sat, 12 Oct 2019 18:27:54 +0200
parent 10323:73938168681c
child 10326:cd1c73c2bdec
comparison
equal deleted inserted replaced
10323:73938168681c 10324:3f4c25425589
227 local global_event = request.method.." "..request.path:match("[^?]*"); 227 local global_event = request.method.." "..request.path:match("[^?]*");
228 228
229 local payload = { request = request, response = response }; 229 local payload = { request = request, response = response };
230 log("debug", "Firing event: %s", global_event); 230 log("debug", "Firing event: %s", global_event);
231 local result = events.fire_event(global_event, payload); 231 local result = events.fire_event(global_event, payload);
232 if result == nil and is_head_request then
233 local global_head_event = "GET "..request.path:match("[^?]*");
234 log("debug", "Firing event: %s", global_head_event);
235 result = events.fire_event(global_head_event, payload);
236 end
232 if result == nil then 237 if result == nil then
233 if not hosts[host] then 238 if not hosts[host] then
234 if hosts[default_host] then 239 if hosts[default_host] then
235 host = default_host; 240 host = default_host;
236 elseif host then 241 elseif host then
247 end 252 end
248 253
249 local host_event = request.method.." "..host..request.path:match("[^?]*"); 254 local host_event = request.method.." "..host..request.path:match("[^?]*");
250 log("debug", "Firing event: %s", host_event); 255 log("debug", "Firing event: %s", host_event);
251 result = events.fire_event(host_event, payload); 256 result = events.fire_event(host_event, payload);
257
258 if result == nil and is_head_request then
259 local host_head_event = "GET "..host..request.path:match("[^?]*");
260 log("debug", "Firing event: %s", host_head_event);
261 result = events.fire_event(host_head_event, payload);
262 end
252 end 263 end
253 if result ~= nil then 264 if result ~= nil then
254 if result ~= true then 265 if result ~= true then
255 local body; 266 local body;
256 local result_type = type(result); 267 local result_type = type(result);