From 51fd2073f805a4ca9dfd7de68c0a722c33094780 Mon Sep 17 00:00:00 2001
From: Matthew Wild <mwild1@gmail.com>
Date: Sat, 21 Mar 2009 23:48:09 +0000
Subject: net.http: Don't throw error on invalid URLs. Fixes #56.

---
 net/http.lua | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'net')

diff --git a/net/http.lua b/net/http.lua
index 1ecbf410..1d22d3e5 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -114,6 +114,14 @@ local function handleerr(err) log("error", "Traceback[http]: %s: %s", tostring(e
 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 @@ function request(u, ex, callback)
 	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
 	
-- 
cgit v1.2.3