diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-02-27 18:30:32 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2005-02-27 18:30:32 +0000 |
commit | 7350bad6f434a8546ed669591e1bbf6ed44a5842 (patch) | |
tree | 3a11d5c51c7a809c143f58e32049d0ed672f0d54 | |
parent | 8d4e240f6ae50d9b22ddc44f5e207018935da907 (diff) | |
download | luasocket-7350bad6f434a8546ed669591e1bbf6ed44a5842.tar.gz luasocket-7350bad6f434a8546ed669591e1bbf6ed44a5842.tar.bz2 luasocket-7350bad6f434a8546ed669591e1bbf6ed44a5842.zip |
Just to check out in the office.
-rw-r--r-- | FIX | 2 | ||||
-rw-r--r-- | src/http.lua | 8 | ||||
-rw-r--r-- | src/tcp.c | 3 | ||||
-rw-r--r-- | src/url.lua | 38 |
4 files changed, 30 insertions, 21 deletions
@@ -1,3 +1,5 @@ | |||
1 | url.absolute was not working when base_url was already parsed | ||
2 | http.request was redirecting even when the location header is empty | ||
1 | tcp{client}:shutdown() was checking for group instead of class. | 3 | tcp{client}:shutdown() was checking for group instead of class. |
2 | tcp{client}:send() now returns i+sent-1... | 4 | tcp{client}:send() now returns i+sent-1... |
3 | get rid of a = socket.try() in the manual, except for protected cases. | 5 | get rid of a = socket.try() in the manual, except for protected cases. |
diff --git a/src/http.lua b/src/http.lua index 5fb59ce..1dff11a 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -173,8 +173,10 @@ local function adjustrequest(reqt) | |||
173 | return nreqt | 173 | return nreqt |
174 | end | 174 | end |
175 | 175 | ||
176 | local function shouldredirect(reqt, code) | 176 | local function shouldredirect(reqt, code, headers) |
177 | return (reqt.redirect ~= false) and | 177 | return headers.location and |
178 | string.gsub(headers.location, "%s", "") ~= "" and | ||
179 | (reqt.redirect ~= false) and | ||
178 | (code == 301 or code == 302) and | 180 | (code == 301 or code == 302) and |
179 | (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") | 181 | (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") |
180 | and (not reqt.nredirects or reqt.nredirects < 5) | 182 | and (not reqt.nredirects or reqt.nredirects < 5) |
@@ -226,7 +228,7 @@ function trequest(reqt) | |||
226 | local code, headers, status | 228 | local code, headers, status |
227 | code, status = h:receivestatusline() | 229 | code, status = h:receivestatusline() |
228 | headers = h:receiveheaders() | 230 | headers = h:receiveheaders() |
229 | if shouldredirect(reqt, code) then | 231 | if shouldredirect(reqt, code, headers) then |
230 | h:close() | 232 | h:close() |
231 | return tredirect(reqt, headers) | 233 | return tredirect(reqt, headers) |
232 | elseif shouldauthorize(reqt, code) then | 234 | elseif shouldauthorize(reqt, code) then |
@@ -228,9 +228,8 @@ static int meth_connect(lua_State *L) | |||
228 | 228 | ||
229 | static int meth_connected(lua_State *L) | 229 | static int meth_connected(lua_State *L) |
230 | { | 230 | { |
231 | static t_tm tm = {-1, -1}; | ||
232 | p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); | 231 | p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); |
233 | int err = sock_connected(&tcp->sock, &tm); | 232 | int err = sock_connected(&tcp->sock, &tcp->tm); |
234 | if (err != IO_DONE) { | 233 | if (err != IO_DONE) { |
235 | lua_pushnil(L); | 234 | lua_pushnil(L); |
236 | lua_pushstring(L, sock_strerror(err)); | 235 | lua_pushstring(L, sock_strerror(err)); |
diff --git a/src/url.lua b/src/url.lua index 8d7b88f..7aa3760 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -194,28 +194,34 @@ end | |||
194 | -- corresponding absolute url | 194 | -- corresponding absolute url |
195 | ----------------------------------------------------------------------------- | 195 | ----------------------------------------------------------------------------- |
196 | function absolute(base_url, relative_url) | 196 | function absolute(base_url, relative_url) |
197 | local base = base.type(base_url) == "table" and base_url or parse(base_url) | 197 | if base.type(base_url) == "table" then |
198 | local relative = parse(relative_url) | 198 | base_parsed = base_url |
199 | if not base then return relative_url | 199 | base_url = build(base_parsed) |
200 | elseif not relative then return base_url | ||
201 | elseif relative.scheme then return relative_url | ||
202 | else | 200 | else |
203 | relative.scheme = base.scheme | 201 | base_parsed = parse(base_url) |
204 | if not relative.authority then | 202 | end |
205 | relative.authority = base.authority | 203 | local relative_parsed = parse(relative_url) |
206 | if not relative.path then | 204 | if not base_parsed then return relative_url |
207 | relative.path = base.path | 205 | elseif not relative_parsed then return base_url |
208 | if not relative.params then | 206 | elseif relative_parsed.scheme then return relative_url |
209 | relative.params = base.params | 207 | else |
210 | if not relative.query then | 208 | relative_parsed.scheme = base_parsed.scheme |
211 | relative.query = base.query | 209 | if not relative_parsed.authority then |
210 | relative_parsed.authority = base_parsed.authority | ||
211 | if not relative_parsed.path then | ||
212 | relative_parsed.path = base_parsed.path | ||
213 | if not relative_parsed.params then | ||
214 | relative_parsed.params = base_parsed.params | ||
215 | if not relative_parsed.query then | ||
216 | relative_parsed.query = base_parsed.query | ||
212 | end | 217 | end |
213 | end | 218 | end |
214 | else | 219 | else |
215 | relative.path = absolute_path(base.path or "", relative.path) | 220 | relative_parsed.path = absolute_path(base_parsed.path or "", |
221 | relative_parsed.path) | ||
216 | end | 222 | end |
217 | end | 223 | end |
218 | return build(relative) | 224 | return build(relative_parsed) |
219 | end | 225 | end |
220 | end | 226 | end |
221 | 227 | ||