3UF6U42R6UH44WC4WRPY2UHJL5S4JO7OBZFVH55CD5OXALHREHHQC return string.gsub(s, "([^A-Za-z0-9_])", function (c)if segment_set[c] then return celse return string.format("%%%02x", string.byte(c)) endend)
return string.gsub(s, "([^A-Za-z0-9_])", function(c)if segment_set[c] thenreturn celsereturn string.format("%%%02x", string.byte(c))endend)
local authority = parsed.authorityif parsed.host thenauthority = parsed.hostif parsed.port then authority = authority .. ":" .. parsed.port endlocal userinfo = parsed.userinfoif parsed.user thenuserinfo = parsed.userif parsed.password thenuserinfo = userinfo .. ":" .. parsed.passwordendendif userinfo then authority = userinfo .. "@" .. authority endend
local authority = parsed.authorityif parsed.host thenauthority = parsed.hostif parsed.port then authority = authority .. ":" .. parsed.port endlocal userinfo = parsed.userinfoif parsed.user thenuserinfo = parsed.userif parsed.password thenuserinfo = userinfo .. ":" .. parsed.passwordendendif userinfo then authority = userinfo .. "@" .. authority endend
local relative_parsed = parse(relative_url)if not base_parsed then return relative_urlelseif not relative_parsed then return base_urlelseif relative_parsed.scheme then return relative_url
local relative_parsed = M.parse(relative_url)if not base_parsed thenreturn relative_urlelseif not relative_parsed thenreturn base_urlelseif relative_parsed.scheme thenreturn relative_url
function parse_path(path)local parsed = {}path = path or ""--path = string.gsub(path, "%s", "")string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end)for i = 1, table.getn(parsed) doparsed[i] = unescape(parsed[i])endif string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 endif string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 endreturn parsed
function M.parse_path(path)local parsed = {}path = path or ""--path = string.gsub(path, "%s", "")string.gsub(path, "([^/]+)", function(s) table.insert(parsed, s) end)for i = 1, #parsed doparsed[i] = M.unescape(parsed[i])endif string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 endif string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 endreturn parsed
function build_path(parsed, unsafe)local path = ""local n = table.getn(parsed)if unsafe thenfor i = 1, n-1 dopath = path .. parsed[i]path = path .. "/"endif n > 0 thenpath = path .. parsed[n]if parsed.is_directory then path = path .. "/" endendelsefor i = 1, n-1 dopath = path .. protect_segment(parsed[i])path = path .. "/"endif n > 0 thenpath = path .. protect_segment(parsed[n])if parsed.is_directory then path = path .. "/" endendendif parsed.is_absolute then path = "/" .. path endreturn path
function M.build_path(parsed, unsafe)local path = ""local n = #parsedif unsafe thenfor i = 1, n - 1 dopath = path .. parsed[i]path = path .. "/"endif n > 0 thenpath = path .. parsed[n]if parsed.is_directory then path = path .. "/" endendelsefor i = 1, n - 1 dopath = path .. protect_segment(parsed[i])path = path .. "/"endif n > 0 thenpath = path .. protect_segment(parsed[n])if parsed.is_directory then path = path .. "/" endendendif parsed.is_absolute then path = "/" .. path endreturn path
return M
function connect(host, port, timeout, create)local c, e = (create or socket.tcp)()if not c then return nil, e end
function M.connect(host, port, timeout, create)local c, err = (create or socket.tcp)()if not c then return nil, err end
return M
if base.type(mesgt.body) == "table" then send_multipart(mesgt)elseif base.type(mesgt.body) == "function" then send_source(mesgt)else send_string(mesgt) end
if base.type(mesgt.body) == "table" thensend_multipart(mesgt)elseif base.type(mesgt.body) == "function" thensend_source(mesgt)elsesend_string(mesgt)end
return M
local mode = "default" -- connection closeif t and t ~= "identity" then mode = "http-chunked"elseif base.tonumber(headers["content-length"]) then mode = "by-length" end
local mode = "default" -- connection closeif t and t ~= "identity" thenmode = "http-chunked"elseif base.tonumber(headers["content-length"]) thenmode = "by-length"end
path = socket.try(reqt.path, "invalid path 'nil'"),params = reqt.params,query = reqt.query,fragment = reqt.fragment
path = socket.try(reqt.path, "invalid path 'nil'"),params = reqt.params,query = reqt.query,fragment = reqt.fragment
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)
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)
request = socket.protect(function(reqt, body)if base.type(reqt) == "string" then return srequest(reqt, body)else return trequest(reqt) end
M.request = socket.protect(function(reqt, body)if base.type(reqt) == "string" thenreturn srequest(reqt, body)elsereturn trequest(reqt)end
return M