diff options
| author | Diego Nehab <diego.nehab@gmail.com> | 2015-08-24 16:41:24 -0300 |
|---|---|---|
| committer | Diego Nehab <diego.nehab@gmail.com> | 2015-08-24 16:41:24 -0300 |
| commit | 46d7e75f3e71d75bf07ae83d7df4aa276e484473 (patch) | |
| tree | 04c7aedb342078dd8dff07154ba6aad4384d00c8 | |
| parent | b6a10ccb68e84f24537917c585873e32e7632885 (diff) | |
| parent | 2314235b3ac62f5519177efadc2a738fd7224ee4 (diff) | |
| download | luasocket-46d7e75f3e71d75bf07ae83d7df4aa276e484473.tar.gz luasocket-46d7e75f3e71d75bf07ae83d7df4aa276e484473.tar.bz2 luasocket-46d7e75f3e71d75bf07ae83d7df4aa276e484473.zip | |
Merge pull request #96 from chastabor/master
Generate headers before proxy changes host and port
| -rw-r--r-- | src/http.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/http.lua b/src/http.lua index d5457f6..45ffa15 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -221,6 +221,15 @@ local function adjustheaders(reqt) | |||
| 221 | lower["authorization"] = | 221 | lower["authorization"] = |
| 222 | "Basic " .. (mime.b64(reqt.user .. ":" .. reqt.password)) | 222 | "Basic " .. (mime.b64(reqt.user .. ":" .. reqt.password)) |
| 223 | end | 223 | end |
| 224 | -- if we have proxy authentication information, pass it along | ||
| 225 | local proxy = reqt.proxy or _M.PROXY | ||
| 226 | if proxy then | ||
| 227 | proxy = url.parse(proxy) | ||
| 228 | if proxy.user and proxy.password then | ||
| 229 | lower["proxy-authorization"] = | ||
| 230 | "Basic " .. (mime.b64(proxy.user .. ":" .. proxy.password)) | ||
| 231 | end | ||
| 232 | end | ||
| 224 | -- override with user headers | 233 | -- override with user headers |
| 225 | for i,v in base.pairs(reqt.headers or lower) do | 234 | for i,v in base.pairs(reqt.headers or lower) do |
| 226 | lower[string.lower(i)] = v | 235 | lower[string.lower(i)] = v |
| @@ -246,10 +255,10 @@ local function adjustrequest(reqt) | |||
| 246 | "invalid host '" .. base.tostring(nreqt.host) .. "'") | 255 | "invalid host '" .. base.tostring(nreqt.host) .. "'") |
| 247 | -- compute uri if user hasn't overriden | 256 | -- compute uri if user hasn't overriden |
| 248 | nreqt.uri = reqt.uri or adjusturi(nreqt) | 257 | nreqt.uri = reqt.uri or adjusturi(nreqt) |
| 249 | -- ajust host and port if there is a proxy | ||
| 250 | nreqt.host, nreqt.port = adjustproxy(nreqt) | ||
| 251 | -- adjust headers in request | 258 | -- adjust headers in request |
| 252 | nreqt.headers = adjustheaders(nreqt) | 259 | nreqt.headers = adjustheaders(nreqt) |
| 260 | -- ajust host and port if there is a proxy | ||
| 261 | nreqt.host, nreqt.port = adjustproxy(nreqt) | ||
| 253 | return nreqt | 262 | return nreqt |
| 254 | end | 263 | end |
| 255 | 264 | ||
