X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;ds=sidebyside;f=net%2Fhttp.lua;h=6ddb19004beb1977b3fe20301487bdbd60ff59b7;hb=f50f4cb01c079cfa913a76313859e469abbda12e;hp=3b783a41c89cefab692f0f29b4bf286065c98452;hpb=6e9cdb4140d8c6cc39478f3cf792441c73805e3c;p=prosody.git diff --git a/net/http.lua b/net/http.lua index 3b783a41..6ddb1900 100644 --- a/net/http.lua +++ b/net/http.lua @@ -20,6 +20,7 @@ local t_insert, t_concat = table.insert, table.concat; local pairs = pairs; local tonumber, tostring, xpcall, select, traceback = tonumber, tostring, xpcall, select, debug.traceback; +local assert, error = assert, error local log = require "util.logger".init("http"); @@ -116,8 +117,17 @@ function request(u, ex, callback) local method, headers, body; + local host, port = req.host, req.port; + local host_header = host; + if (port == "80" and req.scheme == "http") + or (port == "443" and req.scheme == "https") then + port = nil; + elseif port then + host_header = host_header..":"..port; + end + headers = { - ["Host"] = req.host; + ["Host"] = host_header; ["User-Agent"] = "Prosody XMPP Server"; }; @@ -148,12 +158,12 @@ function request(u, ex, callback) if using_https and not ssl_available then error("SSL not available, unable to contact https URL"); end - local port = tonumber(req.port) or (using_https and 443 or 80); + local port_number = port and tonumber(port) or (using_https and 443 or 80); -- Connect the socket, and wrap it with net.server local conn = socket.tcp(); conn:settimeout(10); - local ok, err = conn:connect(req.host, port); + local ok, err = conn:connect(host, port_number); if not ok and err ~= "timeout" then callback(nil, 0, req); return nil, err; @@ -164,7 +174,7 @@ function request(u, ex, callback) sslctx = ex and ex.sslctx or { mode = "client", protocol = "sslv23", options = { "no_sslv2" } }; end - req.handler, req.conn = server.wrapclient(conn, req.host, port, listener, "*a", sslctx); + req.handler, req.conn = assert(server.wrapclient(conn, host, port_number, listener, "*a", sslctx)); req.write = function (...) return req.handler:write(...); end req.callback = function (content, code, request, response) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request, response) end, handleerr)); end