diff options
| author | E. Westbrook <github@westbrook.io> | 2018-07-12 11:07:20 -0600 |
|---|---|---|
| committer | E. Westbrook <github@westbrook.io> | 2019-02-20 02:42:40 -0700 |
| commit | 686f2ce8222077e13ecdf9cf09f43f0b1878a737 (patch) | |
| tree | c92b39051427874a5be863a6203cef8dc6b25b08 | |
| parent | 144fa01c2f204e3b1b13c834f2644d100dba701b (diff) | |
| download | luasocket-686f2ce8222077e13ecdf9cf09f43f0b1878a737.tar.gz luasocket-686f2ce8222077e13ecdf9cf09f43f0b1878a737.tar.bz2 luasocket-686f2ce8222077e13ecdf9cf09f43f0b1878a737.zip | |
http.lua: if default for scheme, omit port number in "Host:" header
| -rw-r--r-- | src/http.lua | 20 |
1 files 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 | |||
| 27 | _M.USERAGENT = socket._VERSION | 27 | _M.USERAGENT = socket._VERSION |
| 28 | 28 | ||
| 29 | -- supported schemes | 29 | -- supported schemes |
| 30 | local SCHEMES = { ["http"] = true } | 30 | local SCHEMES = { |
| 31 | -- default port for document retrieval | 31 | http = { port = 80 } |
| 32 | local PORT = 80 | 32 | , https = { port = 443 }} |
| 33 | |||
| 34 | -- default scheme and port for document retrieval | ||
| 35 | local SCHEME = 'http' | ||
| 36 | local 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 | ||
| 213 | local function adjustheaders(reqt) | 217 | local 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 | ||
| 252 | local function adjustrequest(reqt) | 260 | local function adjustrequest(reqt) |
