mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-26 04:28:20 +01:00
Just to check out in the office.
This commit is contained in:
parent
8d4e240f6a
commit
7350bad6f4
2
FIX
2
FIX
@ -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}:shutdown() was checking for group instead of class.
|
||||||
tcp{client}:send() now returns i+sent-1...
|
tcp{client}:send() now returns i+sent-1...
|
||||||
get rid of a = socket.try() in the manual, except for protected cases.
|
get rid of a = socket.try() in the manual, except for protected cases.
|
||||||
|
@ -173,8 +173,10 @@ local function adjustrequest(reqt)
|
|||||||
return nreqt
|
return nreqt
|
||||||
end
|
end
|
||||||
|
|
||||||
local function shouldredirect(reqt, code)
|
local function shouldredirect(reqt, code, headers)
|
||||||
return (reqt.redirect ~= false) and
|
return headers.location and
|
||||||
|
string.gsub(headers.location, "%s", "") ~= "" and
|
||||||
|
(reqt.redirect ~= false) and
|
||||||
(code == 301 or code == 302) and
|
(code == 301 or code == 302) and
|
||||||
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
|
(not reqt.method or reqt.method == "GET" or reqt.method == "HEAD")
|
||||||
and (not reqt.nredirects or reqt.nredirects < 5)
|
and (not reqt.nredirects or reqt.nredirects < 5)
|
||||||
@ -226,7 +228,7 @@ function trequest(reqt)
|
|||||||
local code, headers, status
|
local code, headers, status
|
||||||
code, status = h:receivestatusline()
|
code, status = h:receivestatusline()
|
||||||
headers = h:receiveheaders()
|
headers = h:receiveheaders()
|
||||||
if shouldredirect(reqt, code) then
|
if shouldredirect(reqt, code, headers) then
|
||||||
h:close()
|
h:close()
|
||||||
return tredirect(reqt, headers)
|
return tredirect(reqt, headers)
|
||||||
elseif shouldauthorize(reqt, code) then
|
elseif shouldauthorize(reqt, code) then
|
||||||
|
@ -228,9 +228,8 @@ static int meth_connect(lua_State *L)
|
|||||||
|
|
||||||
static int meth_connected(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);
|
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) {
|
if (err != IO_DONE) {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_pushstring(L, sock_strerror(err));
|
lua_pushstring(L, sock_strerror(err));
|
||||||
|
38
src/url.lua
38
src/url.lua
@ -194,28 +194,34 @@ end
|
|||||||
-- corresponding absolute url
|
-- corresponding absolute url
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
function absolute(base_url, relative_url)
|
function absolute(base_url, relative_url)
|
||||||
local base = base.type(base_url) == "table" and base_url or parse(base_url)
|
if base.type(base_url) == "table" then
|
||||||
local relative = parse(relative_url)
|
base_parsed = base_url
|
||||||
if not base then return relative_url
|
base_url = build(base_parsed)
|
||||||
elseif not relative then return base_url
|
|
||||||
elseif relative.scheme then return relative_url
|
|
||||||
else
|
else
|
||||||
relative.scheme = base.scheme
|
base_parsed = parse(base_url)
|
||||||
if not relative.authority then
|
end
|
||||||
relative.authority = base.authority
|
local relative_parsed = parse(relative_url)
|
||||||
if not relative.path then
|
if not base_parsed then return relative_url
|
||||||
relative.path = base.path
|
elseif not relative_parsed then return base_url
|
||||||
if not relative.params then
|
elseif relative_parsed.scheme then return relative_url
|
||||||
relative.params = base.params
|
else
|
||||||
if not relative.query then
|
relative_parsed.scheme = base_parsed.scheme
|
||||||
relative.query = base.query
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
relative.path = absolute_path(base.path or "", relative.path)
|
relative_parsed.path = absolute_path(base_parsed.path or "",
|
||||||
|
relative_parsed.path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return build(relative)
|
return build(relative_parsed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user