From 686f2ce8222077e13ecdf9cf09f43f0b1878a737 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Thu, 12 Jul 2018 11:07:20 -0600 Subject: [PATCH] http.lua: if default for scheme, omit port number in "Host:" header --- src/http.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/http.lua b/src/http.lua index a386165..6b26a0a 100644 --- a/src/http.lua +++ b/src/http.lua @@ -27,9 +27,13 @@ _M.TIMEOUT = 60 _M.USERAGENT = socket._VERSION -- supported schemes -local SCHEMES = { ["http"] = true } --- default port for document retrieval -local PORT = 80 +local SCHEMES = { + http = { port = 80 } + , https = { port = 443 }} + +-- default scheme and port for document retrieval +local SCHEME = 'http' +local PORT = SCHEMES[SCHEME].port ----------------------------------------------------------------------------- -- Reads MIME headers from a connection, unfolding where needed @@ -212,10 +216,14 @@ end local function adjustheaders(reqt) -- default headers - local host = string.gsub(reqt.authority, "^.-@", "") + local headhost = reqt.host + local headport = tostring(reqt.port) + local schemeport = tostring(SCHEMES[reqt.scheme].port) + if headport ~= schemeport then + headhost = headhost .. ':' .. headport end local lower = { ["user-agent"] = _M.USERAGENT, - ["host"] = host, + ["host"] = headhost, ["connection"] = "close, TE", ["te"] = "trailers" } @@ -246,7 +254,7 @@ local default = { host = "", port = PORT, path ="/", - scheme = "http" + scheme = SCHEME } local function adjustrequest(reqt)