Mercurial > hg > orthanc
diff OrthancFramework/Sources/Lua/LuaContext.cpp @ 5016:c89ffa13173e
Lua: new "SetHttpTimeout" function
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 13 Jun 2022 16:55:22 +0200 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
line wrap: on
line diff
--- 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<long>(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) {