aboutsummaryrefslogtreecommitdiffstats
path: root/net/http.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-06-26 21:40:01 +0100
committerMatthew Wild <mwild1@gmail.com>2013-06-26 21:40:01 +0100
commit3ad5836d2e94c5399f5291f787ba113e19c9cb40 (patch)
treeba079236f7bcf3f25005c3480e047e8e2f183686 /net/http.lua
parent12877796b2c8f0a4a9c6d3396da7a45a983a0db1 (diff)
downloadprosody-3ad5836d2e94c5399f5291f787ba113e19c9cb40.tar.gz
prosody-3ad5836d2e94c5399f5291f787ba113e19c9cb40.zip
net.http: Include port number (when non-standard) in the Host header of outgoing requests, as per the HTTP RFC
Diffstat (limited to 'net/http.lua')
-rw-r--r--net/http.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/net/http.lua b/net/http.lua
index 3b783a41..b7d2beb9 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -116,8 +116,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 +157,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 +173,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 = 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