Compare commits
No commits in common. "fbef63f9b0d4b4cfc9a2907adab8b5baf31af0f1" and "0aba709fb156263789c699c51d1eb0a3a54ab5c4" have entirely different histories.
fbef63f9b0
...
0aba709fb1
@ -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()
|
@ -48,28 +48,11 @@ local function fileHandler(socket,rtype,path)
|
||||
else
|
||||
socket:write("fUnknown request type")
|
||||
end
|
||||
socket:close()
|
||||
end
|
||||
local function httpHandler(socket,rtype,path)
|
||||
local tPath = fs.segments(path)
|
||||
local proto = table.remove(tPath,1)
|
||||
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
|
||||
socket:write("fHTTP requests are not yet implemented.")
|
||||
socket:close()
|
||||
end
|
||||
|
||||
local function socketHandler(socket)
|
||||
@ -80,7 +63,7 @@ local function socketHandler(socket)
|
||||
line = socket:read()
|
||||
until line
|
||||
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)
|
||||
else
|
||||
path = (cfg.path .. "/" .. path:gsub("../","")):gsub("/+","/")
|
||||
@ -91,5 +74,5 @@ local function socketHandler(socket)
|
||||
end
|
||||
|
||||
while true do
|
||||
os.spawn(socketHandler(minitel.listen(70)),"fserv worker process")
|
||||
os.spawn(socketHandler(minitel.listen(70)))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user