Diff

net/http.lua @ 903:6737d005a84a

net.http: Don't throw error on invalid URLs. Fixes #56.
author Matthew Wild <mwild1@gmail.com>
date Sat, 21 Mar 2009 23:48:09 +0000
parent 739:1def06cd9311
child 923:c63f9bc45a85
line wrap: on
line diff
--- 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