Changeset

4713:9c15fa5192d3

net.http.server: Fire http-error 400 if request fails sanity checks
author Matthew Wild <mwild1@gmail.com>
date Thu, 26 Apr 2012 16:11:08 +0100
parents 4712:4fc99f1b7570
children 4715:4d6ebe54671e
files net/http/server.lua
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/net/http/server.lua	Thu Apr 26 20:07:13 2012 +0500
+++ b/net/http/server.lua	Thu Apr 26 16:11:08 2012 +0100
@@ -170,10 +170,17 @@
 	};
 	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