Skip to content

Commit

Permalink
net fixes & updated corehttp (#47)
Browse files Browse the repository at this point in the history
* updated corehttp
* fixed net
* fix safe functions
  • Loading branch information
cryi authored Nov 4, 2023
1 parent 34adaa9 commit 7fd2a85
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@
ignore = dirty
[submodule "deps/corehttp"]
path = deps/corehttp
url = https://github.com/FreeRTOS/coreHTTP.git
url = https://github.com/alis-is/coreHTTP.git
ignore = dirty
2 changes: 1 addition & 1 deletion config.hjson
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
version: 0.32.0-dev
version: 0.32.0-dev.2
global_modules: false //disables global modules loading (only looks up for modules in cwd)
minify: true
compress: true
Expand Down
2 changes: 1 addition & 1 deletion deps/corehttp
2 changes: 1 addition & 1 deletion deps/lua-corehttp
2 changes: 1 addition & 1 deletion lib/eli/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ function util.generate_safe_functions(fnTable)
if type(v) == "function" and not k:match"^safe_" then
res["safe_" .. k] = function (...)
local result = table.pack(pcall(v, ...))
local msg, code = util.extract_error_info(result[2])
if not result[1] then
local msg, code = util.extract_error_info(result[2])
return result[1], msg, code
end
return table.unpack(result)
Expand Down
16 changes: 16 additions & 0 deletions lib/tests/net.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local test = TEST or require"u-test"
local ok, eliNet = pcall(require, "eli.net")
local eliFs = require"eli.fs"

-- https://postman-echo.com/ ?
local HTTPBIN_URL = os.getenv"HTTPBIN_URL" or "https://httpbin.org/"
Expand Down Expand Up @@ -56,6 +57,21 @@ test["download (progress)"] = function ()
test.assert(_printed:match"(%d+)%%", "no progress detected")
end

test["download_large_file"] = function ()
-- https://github.com/tez-capital/tezpay/releases/download/0.8.5-alpha/tezpay-linux-arm64
-- 07728dbf002a5857d4ecb4b30995fac46d09ea2768680852678fbc222d2cf26e

local ok, error = eliNet.safe_download_file(
"https://github.com/tez-capital/tezpay/releases/download/0.8.5-alpha/tezpay-linux-arm64",
"tmp/tezpay", { followRedirects = true })
test.assert(ok, error)

local ok, hash = eliFs.safe_hash_file("tmp/tezpay", { type = "sha256", hex = true })
test.assert(ok, hash)
test.assert(hash == "07728dbf002a5857d4ecb4b30995fac46d09ea2768680852678fbc222d2cf26e",
"hashes do not match (" .. tostring(hash) .. "<>07728dbf002a5857d4ecb4b30995fac46d09ea2768680852678fbc222d2cf26e)")
end

test["download_file"] = function ()
local ok, error = eliNet.safe_download_file("https://raw.githubusercontent.com/alis-is/eli/main/LICENSE",
"tmp/LICENSE")
Expand Down
52 changes: 26 additions & 26 deletions tools/patches/deps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,32 +246,32 @@ message( ${ZLIBINCLUDEDIR} )
return file
end,
},
[CORE_HTTP_CLIENT_H] = {
validate = function (file)
return file:match"define CORE_HTTP_CLIENT_H_"
end,
patch = function (file)
-- injected code starts with /* injected eli corehttp patch */
local injectedStart = file:find"/%* injected eli corehttp patch %*/"
if injectedStart then
file = file:sub(1, injectedStart - 1)
end
return file .. lustache:render(templates.CORE_HTTP_CLIENT_H, { config = config })
end,
},
[CORE_HTTP_CLIENT_C] = {
validate = function (file)
return file:match"sendHttpHeaders" and file:match"sendHttpHeaders" and file:match"sendHttpData"
end,
patch = function (file)
-- injected code starts with /* injected eli corehttp patch */
local injectedStart = file:find"/%* injected eli corehttp patch %*/"
if injectedStart then
file = file:sub(1, injectedStart - 1)
end
return file .. lustache:render(templates.CORE_HTTP_CLIENT_C, { config = config })
end,
},
-- [CORE_HTTP_CLIENT_H] = {
-- validate = function (file)
-- return file:match"define CORE_HTTP_CLIENT_H_"
-- end,
-- patch = function (file)
-- -- injected code starts with /* injected eli corehttp patch */
-- local injectedStart = file:find"/%* injected eli corehttp patch %*/"
-- if injectedStart then
-- file = file:sub(1, injectedStart - 1)
-- end
-- return file .. lustache:render(templates.CORE_HTTP_CLIENT_H, { config = config })
-- end,
-- },
-- [CORE_HTTP_CLIENT_C] = {
-- validate = function (file)
-- return file:match"sendHttpHeaders" and file:match"sendHttpHeaders" and file:match"sendHttpData"
-- end,
-- patch = function (file)
-- -- injected code starts with /* injected eli corehttp patch */
-- local injectedStart = file:find"/%* injected eli corehttp patch %*/"
-- if injectedStart then
-- file = file:sub(1, injectedStart - 1)
-- end
-- return file .. lustache:render(templates.CORE_HTTP_CLIENT_C, { config = config })
-- end,
-- },
[LUA_COREHTTP_CONFIG_H] = {
validate = function (file)
return file:match"HTTP_USER_AGENT_VALUE"
Expand Down

0 comments on commit 7fd2a85

Please sign in to comment.