Merge pull request #258 from ewestbrook/luasec117

http.lua: if default for scheme, omit port number in "Host:" header
This commit is contained in:
Diego Nehab 2019-02-24 17:48:00 -03:00 committed by GitHub
commit b8f088e868
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,9 +27,13 @@ _M.TIMEOUT = 60
_M.USERAGENT = socket._VERSION _M.USERAGENT = socket._VERSION
-- supported schemes -- supported schemes
local SCHEMES = { ["http"] = true } local SCHEMES = {
-- default port for document retrieval http = { port = 80 }
local 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 -- Reads MIME headers from a connection, unfolding where needed
@ -212,10 +216,14 @@ end
local function adjustheaders(reqt) local function adjustheaders(reqt)
-- default headers -- 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 = { local lower = {
["user-agent"] = _M.USERAGENT, ["user-agent"] = _M.USERAGENT,
["host"] = host, ["host"] = headhost,
["connection"] = "close, TE", ["connection"] = "close, TE",
["te"] = "trailers" ["te"] = "trailers"
} }
@ -246,7 +254,7 @@ local default = {
host = "", host = "",
port = PORT, port = PORT,
path ="/", path ="/",
scheme = "http" scheme = SCHEME
} }
local function adjustrequest(reqt) local function adjustrequest(reqt)