Just to check out in the office.

This commit is contained in:
Diego Nehab 2005-02-27 18:30:32 +00:00
parent 8d4e240f6a
commit 7350bad6f4
4 changed files with 30 additions and 21 deletions

2
FIX
View File

@ -1,3 +1,5 @@
url.absolute was not working when base_url was already parsed
http.request was redirecting even when the location header is empty
tcp{client}:shutdown() was checking for group instead of class.
tcp{client}:send() now returns i+sent-1...
get rid of a = socket.try() in the manual, except for protected cases.

View File

@ -173,8 +173,10 @@ local function adjustrequest(reqt)
return nreqt
end
local function shouldredirect(reqt, code)
return (reqt.redirect ~= false) and
local function shouldredirect(reqt, code, headers)
return headers.location and
string.gsub(headers.location, "%s", "") ~= "" and
(reqt.redirect ~= false) and
(code == 301 or code == 302) and
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
and (not reqt.nredirects or reqt.nredirects < 5)
@ -226,7 +228,7 @@ function trequest(reqt)
local code, headers, status
code, status = h:receivestatusline()
headers = h:receiveheaders()
if shouldredirect(reqt, code) then
if shouldredirect(reqt, code, headers) then
h:close()
return tredirect(reqt, headers)
elseif shouldauthorize(reqt, code) then

View File

@ -228,9 +228,8 @@ static int meth_connect(lua_State *L)
static int meth_connected(lua_State *L)
{
static t_tm tm = {-1, -1};
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1);
int err = sock_connected(&tcp->sock, &tm);
int err = sock_connected(&tcp->sock, &tcp->tm);
if (err != IO_DONE) {
lua_pushnil(L);
lua_pushstring(L, sock_strerror(err));

View File

@ -194,28 +194,34 @@ end
-- corresponding absolute url
-----------------------------------------------------------------------------
function absolute(base_url, relative_url)
local base = base.type(base_url) == "table" and base_url or parse(base_url)
local relative = parse(relative_url)
if not base then return relative_url
elseif not relative then return base_url
elseif relative.scheme then return relative_url
if base.type(base_url) == "table" then
base_parsed = base_url
base_url = build(base_parsed)
else
relative.scheme = base.scheme
if not relative.authority then
relative.authority = base.authority
if not relative.path then
relative.path = base.path
if not relative.params then
relative.params = base.params
if not relative.query then
relative.query = base.query
base_parsed = parse(base_url)
end
local relative_parsed = parse(relative_url)
if not base_parsed then return relative_url
elseif not relative_parsed then return base_url
elseif relative_parsed.scheme then return relative_url
else
relative_parsed.scheme = base_parsed.scheme
if not relative_parsed.authority then
relative_parsed.authority = base_parsed.authority
if not relative_parsed.path then
relative_parsed.path = base_parsed.path
if not relative_parsed.params then
relative_parsed.params = base_parsed.params
if not relative_parsed.query then
relative_parsed.query = base_parsed.query
end
end
else
relative.path = absolute_path(base.path or "", relative.path)
relative_parsed.path = absolute_path(base_parsed.path or "",
relative_parsed.path)
end
end
return build(relative)
return build(relative_parsed)
end
end