Fine tunned modules scheme.

Adjusted client modules.
Fixed proxy bug in http.
This commit is contained in:
Diego Nehab 2004-10-11 06:18:57 +00:00
parent a04f15d1ca
commit 1e5e8b5ce5
16 changed files with 46 additions and 24 deletions

View file

@ -113,8 +113,9 @@ end
-----------------------------------------------------------------------------
-- High level HTTP API
-----------------------------------------------------------------------------
local function uri(reqt)
local function adjusturi(reqt)
local u = reqt
-- if there is a proxy, we need the full url. otherwise, just a part.
if not reqt.proxy and not PROXY then
u = {
path = socket.try(reqt.path, "invalid path 'nil'"),
@ -126,6 +127,16 @@ local function uri(reqt)
return url.build(u)
end
local function adjustproxy(reqt)
local proxy = reqt.proxy or PROXY
if proxy then
proxy = url.parse(proxy)
return proxy.host, proxy.port or 3128
else
return reqt.host, reqt.port
end
end
local function adjustheaders(headers, host)
local lower = {}
-- override with user values
@ -152,7 +163,9 @@ local function adjustrequest(reqt)
for i,v in reqt do nreqt[i] = reqt[i] end
socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'")
-- compute uri if user hasn't overriden
nreqt.uri = nreqt.uri or uri(nreqt)
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.headers, nreqt.host)
return nreqt