net.http.server: Try default_host if client sent no host anywhere, otherwise... fail. It's 2012.
authorMatthew Wild <mwild1@gmail.com>
Sat, 28 Apr 2012 01:13:49 +0100
changeset 4740 bd9c8bc8036f
parent 4739 f1d32a0dc057
child 4741 0653476ac3a3
net.http.server: Try default_host if client sent no host anywhere, otherwise... fail. It's 2012.
net/http/server.lua
--- a/net/http/server.lua	Sat Apr 28 00:51:36 2012 +0100
+++ b/net/http/server.lua	Sat Apr 28 01:13:49 2012 +0100
@@ -174,15 +174,15 @@
 
 	-- Some sanity checking
 	local err_code, err;
-	if not host then
-		err_code, err = 400, "Missing or invalid 'Host' header";
-	elseif not request.path then
+	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 = 404, "Unknown host: "..host;
+			err_code, err = 400, "Missing or invalid 'Host' header";
 		end
 	end