Changes from ages ago

This commit is contained in:
Ryan Ward 2023-06-26 10:08:05 -04:00
parent e2503cf103
commit 50a6cf88f4
4 changed files with 33 additions and 11 deletions

View File

@ -3,19 +3,40 @@ local net = require("lnet.tcp")
local multi, thread = require("multi"):init()
local http = require("lnet.http")
--local https = require("lnet.https")
local https = require("ssl.https")
multi:newThread("Download Test",function()
local data = http.request("http://zjcdn.mangafox.me/store/manga/14765/01-001.0/compressed/t001.jpg")
-- multi:newThread("Download Test",function()
-- http.request:holdMe(false) -- Gain Access to the return manager
-- local data = http.request {
-- url = "http://files.luaforge.net/releases/luaforwindows/luaforwindows/5.1.4-35/LuaForWindows_v5.1.4-35.exe",
-- sink = ltn12.sink.file(io.open("test.exe","wb"))
-- }
-- local t={}
-- data.OnStatus(function(part,whole)
-- local per = math.ceil((part/whole)*100)
-- if not t[per] then
-- print("T1",per)
-- t[per] = true
-- end
-- end)
-- local c = os.clock()
-- thread.hold(data.connect())
-- print("Done!",os.clock()-c)
-- end)
multi:newThread("Download Test 2",function()--https://erowall.com/download_img.php?dimg=16911&raz=2560x1600
local data,err = https.request("https://erowall.com/download_img.php?dimg=16911&raz=2560x1600")
local file = io.open("test.jpg","wb")
file:write(data)
file:flush()
file:close()
print("Done!")
os.exit()
end).OnError(function(self,err)
print(">>",err)
end)
multi:newThread("Timer",function()
end)
-- local client = net.newCastedClient("Test")--net:newTCPClient("localhost",12345)
-- client:send("Test!")

View File

@ -174,6 +174,7 @@ function metat.__index:receivebody(headers, sink, step)
for i=1,math.floor(length/default_block_size) do
thread.yield()
ret = self.try(ltn12.pump.step(socket.source(mode, self.c, default_block_size), sink, step))
thread.pushStatus(i,math.floor(length/default_block_size))
end
if lp~=0 then
ret = self.try(ltn12.pump.step(socket.source(mode, self.c, lp), sink, step))
@ -301,7 +302,7 @@ local trequest, tredirect
end
-- We don't need to protect this function the thread:newFunction wrapper handles errors for us
trequest = thread:newFunction(function(reqt)
function trequest(reqt)
-- we loop until we get what we want, or
-- until we are sure there is no way to get it
local nreqt = adjustrequest(reqt)
@ -338,7 +339,7 @@ trequest = thread:newFunction(function(reqt)
end
h:close()
return 1, code, headers, status
end,true)
end
local function srequest(u, b)
local t = {}
@ -363,9 +364,9 @@ local function srequest(u, b)
end
end
_M.request = function(reqt, body)
_M.request = thread:newFunction(function(reqt, body)
if base.type(reqt) == "string" then return srequest(reqt, body)
else return trequest(reqt) end
end
end,true)
return _M

View File

@ -9,7 +9,7 @@
local socket = require("socket")
local ssl = require("ssl")
local ltn12 = require("ltn12")
local http = require("lnet.http") -- Only real change that was needed to get things working
local http = require("lnet.http")
local url = require("socket.url")
local try = socket.try
@ -143,4 +143,4 @@ end
_M.request = request
_M.tcp = tcp
return _M
return _M

BIN
test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 MiB