aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego.nehab@gmail.com>2019-02-24 17:48:00 -0300
committerGitHub <noreply@github.com>2019-02-24 17:48:00 -0300
commitb8f088e868d9086d3dc97b11c3e172b047813e7c (patch)
treeaf19fb9639647db360667765751cf95af80fa7ae
parentc5cef32897b9f4f91509f1d65aeefb9a6634c250 (diff)
parent686f2ce8222077e13ecdf9cf09f43f0b1878a737 (diff)
downloadluasocket-b8f088e868d9086d3dc97b11c3e172b047813e7c.tar.gz
luasocket-b8f088e868d9086d3dc97b11c3e172b047813e7c.tar.bz2
luasocket-b8f088e868d9086d3dc97b11c3e172b047813e7c.zip
Merge pull request #258 from ewestbrook/luasec117
http.lua: if default for scheme, omit port number in "Host:" header
-rw-r--r--src/http.lua20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/http.lua b/src/http.lua
index 8bda0d8..fb729b2 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -27,9 +27,13 @@ _M.TIMEOUT = 60
27_M.USERAGENT = socket._VERSION 27_M.USERAGENT = socket._VERSION
28 28
29-- supported schemes 29-- supported schemes
30local SCHEMES = { ["http"] = true } 30local SCHEMES = {
31-- default port for document retrieval 31 http = { port = 80 }
32local PORT = 80 32 , https = { port = 443 }}
33
34-- default scheme and port for document retrieval
35local SCHEME = 'http'
36local PORT = SCHEMES[SCHEME].port
33 37
34----------------------------------------------------------------------------- 38-----------------------------------------------------------------------------
35-- Reads MIME headers from a connection, unfolding where needed 39-- Reads MIME headers from a connection, unfolding where needed
@@ -212,10 +216,14 @@ end
212 216
213local function adjustheaders(reqt) 217local function adjustheaders(reqt)
214 -- default headers 218 -- default headers
215 local host = string.gsub(reqt.authority, "^.-@", "") 219 local headhost = reqt.host
220 local headport = tostring(reqt.port)
221 local schemeport = tostring(SCHEMES[reqt.scheme].port)
222 if headport ~= schemeport then
223 headhost = headhost .. ':' .. headport end
216 local lower = { 224 local lower = {
217 ["user-agent"] = _M.USERAGENT, 225 ["user-agent"] = _M.USERAGENT,
218 ["host"] = host, 226 ["host"] = headhost,
219 ["connection"] = "close, TE", 227 ["connection"] = "close, TE",
220 ["te"] = "trailers" 228 ["te"] = "trailers"
221 } 229 }
@@ -246,7 +254,7 @@ local default = {
246 host = "", 254 host = "",
247 port = PORT, 255 port = PORT,
248 path ="/", 256 path ="/",
249 scheme = "http" 257 scheme = SCHEME
250} 258}
251 259
252local function adjustrequest(reqt) 260local function adjustrequest(reqt)