net.http: Don't throw error on invalid URLs. Fixes #56.
authorMatthew Wild <mwild1@gmail.com>
Sat, 21 Mar 2009 23:48:09 +0000
changeset 903 6737d005a84a
parent 902 00daf63c129e
child 904 0205dcd0854a
net.http: Don't throw error on invalid URLs. Fixes #56.
net/http.lua
--- a/net/http.lua	Sat Mar 21 21:47:09 2009 +0000
+++ b/net/http.lua	Sat Mar 21 23:48:09 2009 +0000
@@ -114,6 +114,14 @@
 function request(u, ex, callback)
 	local req = url.parse(u);
 	
+	if not (req and req.host) then
+		return nil, "invalid-url";
+	end
+	
+	if not req.path then
+		req.path = "/";
+	end
+	
 	local custom_headers, body;
 	local default_headers = { ["Host"] = req.host, ["User-Agent"] = "Prosody XMPP Server" }
 	
@@ -139,6 +147,7 @@
 	req.conn:settimeout(0);
 	local ok, err = req.conn:connect(req.host, req.port or 80);
 	if not ok and err ~= "timeout" then
+		callback(nil, 0, req);
 		return nil, err;
 	end