From 36aa87e03158451df8e51bf8dcd3942134e3d8d8 Mon Sep 17 00:00:00 2001 From: Charles Tabor Date: Fri, 21 Mar 2014 14:25:44 -0500 Subject: [PATCH 1/2] Generate headers before proxy changes host and port --- src/http.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/http.lua b/src/http.lua index 1d0eb50..204a841 100644 --- a/src/http.lua +++ b/src/http.lua @@ -247,10 +247,10 @@ local function adjustrequest(reqt) "invalid host '" .. base.tostring(nreqt.host) .. "'") -- compute uri if user hasn't overriden nreqt.uri = reqt.uri or adjusturi(nreqt) - -- ajust host and port if there is a proxy - nreqt.host, nreqt.port = adjustproxy(nreqt) -- adjust headers in request nreqt.headers = adjustheaders(nreqt) + -- ajust host and port if there is a proxy + nreqt.host, nreqt.port = adjustproxy(nreqt) return nreqt end @@ -353,4 +353,4 @@ _M.request = socket.protect(function(reqt, body) else return trequest(reqt) end end) -return _M \ No newline at end of file +return _M From 2314235b3ac62f5519177efadc2a738fd7224ee4 Mon Sep 17 00:00:00 2001 From: Charles Tabor Date: Thu, 27 Mar 2014 14:40:04 -0500 Subject: [PATCH 2/2] Add proxy authentication headers if present. --- src/http.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/http.lua b/src/http.lua index 204a841..2b4a45e 100644 --- a/src/http.lua +++ b/src/http.lua @@ -222,6 +222,15 @@ local function adjustheaders(reqt) lower["authorization"] = "Basic " .. (mime.b64(reqt.user .. ":" .. reqt.password)) end + -- if we have proxy authentication information, pass it along + local proxy = reqt.proxy or _M.PROXY + if proxy then + proxy = url.parse(proxy) + if proxy.user and proxy.password then + lower["proxy-authorization"] = + "Basic " .. (mime.b64(proxy.user .. ":" .. proxy.password)) + end + end -- override with user headers for i,v in base.pairs(reqt.headers or lower) do lower[string.lower(i)] = v