From e77f1792005088f55353c6c85fe9335e60772754 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Fri, 26 Mar 2004 00:18:41 +0000 Subject: Adjusted some of the broken examples. --- etc/check-links.lua | 41 ++++++++++++++++------------------------- etc/get.lua | 3 +-- 2 files changed, 17 insertions(+), 27 deletions(-) (limited to 'etc') diff --git a/etc/check-links.lua b/etc/check-links.lua index c45131c..03ca6de 100644 --- a/etc/check-links.lua +++ b/etc/check-links.lua @@ -9,11 +9,11 @@ socket.http.TIMEOUT = 10 cache = {} function readfile(path) - path = socket.code.unescape(path) - local file, error = openfile(path, "r") + path = socket.url.unescape(path) + local file, error = io.open(path, "r") if file then - local body = read(file, "*a") - closefile(file) + local body = file:read("*a") + file:close() return body else return nil, error end end @@ -23,20 +23,14 @@ function getstatus(url) if cache[url] then return cache[url] end local res if parsed.scheme == "http" then - local request = { url = url } - local response = { body_cb = function(chunk, err) - return nil - end } - local blocksize = socket.http.BLOCKSIZE - socket.http.BLOCKSIZE = 1 - response = socket.http.request_cb(request, response) - socket.http.BLOCKSIZE = blocksize + local request = { url = url, method = "HEAD" } + local response = socket.http.request(request) if response.code == 200 then res = nil else res = response.status or response.error end elseif parsed.scheme == "file" then - local file, error = openfile(Code.unescape(parsed.path), "r") + local file, error = io.open(socket.url.unescape(parsed.path), "r") if file then - closefile(file) + file:close() res = nil else res = error end else res = string.format("unhandled scheme '%s'", parsed.scheme) end @@ -46,15 +40,12 @@ end function retrieve(url) local parsed = socket.url.parse(url, { scheme = "file" }) - local base, body, error - base = url + local body, headers, code, error + local base = url if parsed.scheme == "http" then - local response = socket.http.request{url = url} - if response.code ~= 200 then - error = response.status or response.error - else - base = response.headers.location or url - body = response.body + body, headers, code, error = socket.http.get(url) + if code == 200 then + base = base or headers.location end elseif parsed.scheme == "file" then body, error = readfile(parsed.path) @@ -67,13 +58,13 @@ function getlinks(body, base) body = string.gsub(body, "%<%!%-%-.-%-%-%>", "") local links = {} -- extract links - string.gsub(body, '[Hh][Rr][Ee][Ff]%s*=%s*"([^"]*)"', function(href) + body = string.gsub(body, '[Hh][Rr][Ee][Ff]%s*=%s*"([^"]*)"', function(href) table.insert(links, socket.url.absolute(base, href)) end) - string.gsub(body, "[Hh][Rr][Ee][Ff]%s*=%s*'([^']*)'", function(href) + body = string.gsub(body, "[Hh][Rr][Ee][Ff]%s*=%s*'([^']*)'", function(href) table.insert(links, socket.url.absolute(base, href)) end) - string.gsub(body, "[Hh][Rr][Ee][Ff]%s*=%s*(%a+)", function(href) + string.gsub(body, "[Hh][Rr][Ee][Ff]%s*=%s*(.-)>", function(href) table.insert(links, socket.url.absolute(base, href)) end) return links diff --git a/etc/get.lua b/etc/get.lua index eafebda..aa29ec2 100644 --- a/etc/get.lua +++ b/etc/get.lua @@ -71,12 +71,11 @@ function stats(size) io.stderr:write("\r", gauge(got, delta, size)) io.stderr:flush() end - return chunk else -- close up io.stderr:write("\r", gauge(got, delta), "\n") - return "" end + return chunk end end -- cgit v1.2.3-55-g6feb