net.xmppclient_listener: Add small comment
[prosody.git] / net / http.lua
index 1ecbf41079f4ee6837e2178cb675b933efa74fbe..b39cc6fbc7de5d2940e61e5da41f2472eb194c5c 100644 (file)
@@ -9,13 +9,12 @@ local connlisteners_get = require "net.connlisteners".get;
 local listener = connlisteners_get("httpclient") or error("No httpclient listener!");
 
 local t_insert, t_concat = table.insert, table.concat;
-local tonumber, tostring, pairs, xpcall, select, debug_traceback = 
-        tonumber, tostring, pairs, xpcall, select, debug.traceback;
+local tonumber, tostring, pairs, xpcall, select, debug_traceback, char = 
+        tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char;
 
 local log = require "util.logger".init("http");
 local print = function () end
 
-local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
 local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end
 
 module "http"
@@ -114,6 +113,15 @@ 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
+               callback(nil, 0, req);
+               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