Compare commits

..

No commits in common. "fbef63f9b0d4b4cfc9a2907adab8b5baf31af0f1" and "0aba709fb156263789c699c51d1eb0a3a54ab5c4" have entirely different histories.

2 changed files with 5 additions and 42 deletions

View File

@ -1,20 +0,0 @@
local tA = {...}
local url = tA[1]
local path = tA[2]
local R=component.invoke(component.list("internet")(),"request",url)
if not R then return false end
local f=io.open(path,"wb")
if not f then return false end
repeat
coroutine.yield()
until R.finishConnect()
local code, message, headers = R.response()
if code > 299 or code < 200 then
return false, code, message
end
repeat
coroutine.yield()
ns = R.read(2048)
f:write(ns or "")
until not ns
f:close()

View File

@ -48,28 +48,11 @@ local function fileHandler(socket,rtype,path)
else else
socket:write("fUnknown request type") socket:write("fUnknown request type")
end end
socket:close()
end end
local function httpHandler(socket,rtype,path) local function httpHandler(socket,rtype,path)
local tPath = fs.segments(path) socket:write("fHTTP requests are not yet implemented.")
local proto = table.remove(tPath,1) socket:close()
local url = string.format("%s://%s",proto,table.concat(tPath,"/"))
local request = component.invoke(component.list("internet")(),"request",url)
repeat
coroutine.yield()
until request.finishConnect()
local code, message, headers = request.response()
if code < 200 or code > 299 then
socket:write(string.format("f%d\n%s",code,message))
else
local data = ""
repeat
coroutine.yield()
data = request.read()
if data then
socket:write(data)
end
until not data
end
end end
local function socketHandler(socket) local function socketHandler(socket)
@ -80,7 +63,7 @@ local function socketHandler(socket)
line = socket:read() line = socket:read()
until line until line
local rtype, path = line:match("(.)(.+)") local rtype, path = line:match("(.)(.+)")
if fs.segments(path)[1] == "http" or fs.segments(path)[1] == "https" then if path:sub(1,6) == "/http/" or path:sub(1,5) == "http/" then
httpHandler(socket,rtype,path) httpHandler(socket,rtype,path)
else else
path = (cfg.path .. "/" .. path:gsub("../","")):gsub("/+","/") path = (cfg.path .. "/" .. path:gsub("../","")):gsub("/+","/")
@ -91,5 +74,5 @@ local function socketHandler(socket)
end end
while true do while true do
os.spawn(socketHandler(minitel.listen(70)),"fserv worker process") os.spawn(socketHandler(minitel.listen(70)))
end end