Skip to content

Commit

Permalink
Added the LuaSimpleWinHttp library for HTTP(S) client implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
madmaxoft committed Mar 22, 2022
1 parent 9928362 commit 30471f1
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
[submodule "lib/lua-cjson"]
path = lib/lua-cjson
url = https://github.com/madmaxoft/lua-cjson
[submodule "lib/LuaSimpleWinHttp"]
path = lib/LuaSimpleWinHttp
url = https://github.com/madmaxoft/LuaSimpleWinHttp.git
[submodule "lib/fmt"]
path = lib/fmt
url = https://github.com/madmaxoft/fmt
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ add_subdirectory(lzlib)
add_subdirectory(luasocket)
add_subdirectory(lsqlite3)
add_subdirectory(lua-cjson)
add_subdirectory(fmt)
add_subdirectory(LuaSimpleWinHttp)
1 change: 1 addition & 0 deletions lib/LuaSimpleWinHttp
Submodule LuaSimpleWinHttp added at 69a3cf
1 change: 1 addition & 0 deletions lib/fmt
Submodule fmt added at d416a9
2 changes: 1 addition & 1 deletion lib/lua
Submodule lua updated 1 files
+4 −5 CMakeLists.txt
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ target_link_libraries(LunaPaak
luasocket
lsqlite3
cjson
LuaSimpleWinHttp
)


Expand All @@ -53,6 +54,7 @@ set(TESTS
Sqlite
Lfs
CJson
LuaSimpleWinHttp
)


Expand Down
3 changes: 3 additions & 0 deletions src/LunaPaak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern "C"
#include <lualib.h>
#include <lauxlib.h>
#include <lfs.h>
#include <LuaSimpleWinHttp.h>

// lzlib fwd:
extern int luaopen_zlib(lua_State *);
Expand Down Expand Up @@ -244,6 +245,8 @@ int main(int argc, char * argv[])
lua_pop(L, 1);
luaL_requiref(L, "cjson.safe", &luaopen_cjson, false);
luaopen_cjson_safe(L);
lua_pop(L, 1);
luaopen_LuaSimpleWinHttp(L);
lua_settop(L, 0); // Trim off all excess values left over by the reg functions

// Store the args to the script in a separate "arg" global:
Expand Down
74 changes: 74 additions & 0 deletions tests/LuaSimpleWinHttp.luna
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
print("LuaSimpleWinHttp test starting")

local lswh = require("LuaSimpleWinHttp")


local function tryCustomHeaders()
print("Sending a GET request...")
local options =
{
headers =
{
"Custom-Header: blablabla",
"Custom2: bleble",
},
}
local resp, code, status, hdrs = assert(lswh.get("https://github.com", options))
print("code = " .. tostring(code))
print("status = " .. tostring(status))
print("hdrs:")
for _, hdr in ipairs(hdrs) do
print(" " .. hdr)
end
print("(done)")
print("resp(" .. type(resp) .. "): " .. tostring(resp))
end





local function tryJsonApi()
print("Sending a POST(JSON) request...")
local json = '{"title":"foo", "body":"bar", "userId":1}'
local resp, statusCode, _, hdrs = assert(lswh.post(
"https://jsonplaceholder.typicode.com/posts",
json,
"application/json; charset=UTF-8"
))
print("API resp: " .. tostring(resp))
print("-------")
print("hdrs:")
for _, hdr in ipairs(hdrs) do
print(" " .. hdr)
end
print("(done)")
end



local function tryWebDav()
print("Sending a PROPFIND request...")
local resp, code, status, hdrs = assert(lswh.request("PROPFIND", "https://www.google.com/calendar/dav", "", ""))
print("code = " .. tostring(code))
print("status = " .. tostring(status))
print("hdrs:")
for _, hdr in ipairs(hdrs) do
print(" " .. hdr)
end
print("(done)")
print("resp(" .. type(resp) .. "): " .. tostring(resp))
end





tryJsonApi()
tryWebDav()
tryCustomHeaders()




print("LuaSimpleWinHttp test finished")

0 comments on commit 30471f1

Please sign in to comment.