diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-10-11 06:18:57 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-10-11 06:18:57 +0000 |
commit | 1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a (patch) | |
tree | 35012ac4464bf4a3c8ed942495ef37319b6c9ad1 /src/http.lua | |
parent | a04f15d1ca440006a53bd0d9f98c12e5abebd969 (diff) | |
download | luasocket-1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a.tar.gz luasocket-1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a.tar.bz2 luasocket-1e5e8b5ce5573fddc7060dae3c1bf2c02788b35a.zip |
Fine tunned modules scheme.
Adjusted client modules.
Fixed proxy bug in http.
Diffstat (limited to 'src/http.lua')
-rw-r--r-- | src/http.lua | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/http.lua b/src/http.lua index 8ea4c47..b265650 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -113,8 +113,9 @@ end | |||
113 | ----------------------------------------------------------------------------- | 113 | ----------------------------------------------------------------------------- |
114 | -- High level HTTP API | 114 | -- High level HTTP API |
115 | ----------------------------------------------------------------------------- | 115 | ----------------------------------------------------------------------------- |
116 | local function uri(reqt) | 116 | local function adjusturi(reqt) |
117 | local u = reqt | 117 | local u = reqt |
118 | -- if there is a proxy, we need the full url. otherwise, just a part. | ||
118 | if not reqt.proxy and not PROXY then | 119 | if not reqt.proxy and not PROXY then |
119 | u = { | 120 | u = { |
120 | path = socket.try(reqt.path, "invalid path 'nil'"), | 121 | path = socket.try(reqt.path, "invalid path 'nil'"), |
@@ -126,6 +127,16 @@ local function uri(reqt) | |||
126 | return url.build(u) | 127 | return url.build(u) |
127 | end | 128 | end |
128 | 129 | ||
130 | local function adjustproxy(reqt) | ||
131 | local proxy = reqt.proxy or PROXY | ||
132 | if proxy then | ||
133 | proxy = url.parse(proxy) | ||
134 | return proxy.host, proxy.port or 3128 | ||
135 | else | ||
136 | return reqt.host, reqt.port | ||
137 | end | ||
138 | end | ||
139 | |||
129 | local function adjustheaders(headers, host) | 140 | local function adjustheaders(headers, host) |
130 | local lower = {} | 141 | local lower = {} |
131 | -- override with user values | 142 | -- override with user values |
@@ -152,7 +163,9 @@ local function adjustrequest(reqt) | |||
152 | for i,v in reqt do nreqt[i] = reqt[i] end | 163 | for i,v in reqt do nreqt[i] = reqt[i] end |
153 | socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") | 164 | socket.try(nreqt.host, "invalid host '" .. tostring(nreqt.host) .. "'") |
154 | -- compute uri if user hasn't overriden | 165 | -- compute uri if user hasn't overriden |
155 | nreqt.uri = nreqt.uri or uri(nreqt) | 166 | nreqt.uri = reqt.uri or adjusturi(nreqt) |
167 | -- ajust host and port if there is a proxy | ||
168 | nreqt.host, nreqt.port = adjustproxy(nreqt) | ||
156 | -- adjust headers in request | 169 | -- adjust headers in request |
157 | nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) | 170 | nreqt.headers = adjustheaders(nreqt.headers, nreqt.host) |
158 | return nreqt | 171 | return nreqt |