# HG changeset patch # User Alain Mazy # Date 1655132122 -7200 # Node ID c89ffa13173e6af7e985a58163ba5b550e164203 # Parent 5b41a8a77cf148e2e12a93ac1a1290c1ddf60131 Lua: new "SetHttpTimeout" function diff -r 5b41a8a77cf1 -r c89ffa13173e NEWS --- a/NEWS Fri Jun 10 06:37:48 2022 +0200 +++ b/NEWS Mon Jun 13 16:55:22 2022 +0200 @@ -1,6 +1,12 @@ Pending changes in the mainline =========================== +General +------- + +* Lua: new "SetHttpTimeout" function + + Maintenance ----------- diff -r 5b41a8a77cf1 -r c89ffa13173e OrthancFramework/Sources/Lua/LuaContext.cpp --- a/OrthancFramework/Sources/Lua/LuaContext.cpp Fri Jun 10 06:37:48 2022 +0200 +++ b/OrthancFramework/Sources/Lua/LuaContext.cpp Mon Jun 13 16:55:22 2022 +0200 @@ -183,6 +183,32 @@ #if ORTHANC_ENABLE_CURL == 1 + int LuaContext::SetHttpTimeout(lua_State *state) + { + LuaContext& that = GetLuaContext(state); + + // Check the types of the arguments + int nArgs = lua_gettop(state); + if (nArgs != 1 || + !lua_isnumber(state, 1)) // Timeout + { + LOG(ERROR) << "Lua: Bad parameters to SetHttpTimeout()"; + } + else + { + // Configure the HTTP client + // Convert to "int" if truncation does not loose precision + long timeout = static_cast(lua_tonumber(state, 1)); + + that.httpClient_.SetTimeout(timeout); + } + + return 0; + } +#endif + + +#if ORTHANC_ENABLE_CURL == 1 bool LuaContext::AnswerHttpQuery(lua_State* state) { std::string str; @@ -566,6 +592,7 @@ lua_register(lua_, "HttpPut", CallHttpPut); lua_register(lua_, "HttpDelete", CallHttpDelete); lua_register(lua_, "SetHttpCredentials", SetHttpCredentials); + lua_register(lua_, "SetHttpTimeout", SetHttpTimeout); #endif SetGlobalVariable("_LuaContext", this); @@ -620,15 +647,6 @@ } -#if ORTHANC_ENABLE_CURL == 1 - void LuaContext::SetHttpCredentials(const char* username, - const char* password) - { - httpClient_.SetCredentials(username, password); - } -#endif - - void LuaContext::Execute(Json::Value& output, const std::string& command) { diff -r 5b41a8a77cf1 -r c89ffa13173e OrthancFramework/Sources/Lua/LuaContext.h --- a/OrthancFramework/Sources/Lua/LuaContext.h Fri Jun 10 06:37:48 2022 +0200 +++ b/OrthancFramework/Sources/Lua/LuaContext.h Mon Jun 13 16:55:22 2022 +0200 @@ -70,6 +70,7 @@ #if ORTHANC_ENABLE_CURL == 1 static int SetHttpCredentials(lua_State *state); + static int SetHttpTimeout(lua_State *state); static int CallHttpPostOrPut(lua_State *state, HttpMethod method); static int CallHttpGet(lua_State *state); @@ -105,11 +106,6 @@ bool IsExistingFunction(const char* name); -#if ORTHANC_ENABLE_CURL == 1 - void SetHttpCredentials(const char* username, - const char* password); -#endif - void RegisterFunction(const char* name, lua_CFunction func); diff -r 5b41a8a77cf1 -r c89ffa13173e TODO --- a/TODO Fri Jun 10 06:37:48 2022 +0200 +++ b/TODO Mon Jun 13 16:55:22 2022 +0200 @@ -244,8 +244,7 @@ Lua === -* Configure HTTP headers from Lua (in HttpGet(), HttpPost(), - HttpPut(), HttpDelete(), RestApiGet(), RestApiPost(), RestApiPut() +* Configure HTTP headers from Lua (in RestApiPost(), RestApiPut() and RestApiDelete(). https://groups.google.com/forum/#!msg/orthanc-users/WNnW187OILM/6XX_bm96BwAJ