From a54e59650fb3aef98485286f3ffaf5cdf6140dab Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 26 Apr 2012 16:11:08 +0100 Subject: net.http.server: Fire http-error 400 if request fails sanity checks --- net/http/server.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'net/http') diff --git a/net/http/server.lua b/net/http/server.lua index deaa44cd..938e676d 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -170,10 +170,17 @@ function handle_request(conn, request, finish_cb) }; conn._http_open_response = response; + local err; if not request.headers.host then + err = "No 'Host' header"; + elseif not request.path then + err = "Invalid path"; + end + + if err then response.status_code = 400; response.headers.content_type = "text/html"; - response:send(events.fire_event("http-error", { code = 400, message = "No 'Host' header" })); + response:send(events.fire_event("http-error", { code = 400, message = err })); else local host = request.headers.host; if host then -- cgit v1.2.3