# HG changeset patch # User Sebastien Jodogne # Date 1435746619 -7200 # Node ID d26c8a93d05aa9428209d868855c826937f66eec # Parent b2b09a3dbd8e6bbd3f066adf3ed6d0737714bc0e refactoring: SimpleGet diff -r b2b09a3dbd8e -r d26c8a93d05a OrthancServer/LuaScripting.cpp --- a/OrthancServer/LuaScripting.cpp Wed Jul 01 12:09:58 2015 +0200 +++ b/OrthancServer/LuaScripting.cpp Wed Jul 01 12:30:19 2015 +0200 @@ -82,14 +82,10 @@ const char* uri = lua_tostring(state, 1); bool builtin = (nArgs == 2 ? lua_toboolean(state, 2) : false); - IHttpHandler& handler = (builtin ? - serverContext->GetHttpHandler().GetOrthancRestApi() : - serverContext->GetHttpHandler()); - - std::string str; - if (HttpToolbox::SimpleGet(str, handler, uri)) + std::string result; + if (HttpToolbox::SimpleGet(result, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), uri)) { - lua_pushstring(state, str.c_str()); + lua_pushstring(state, result.c_str()); } else { diff -r b2b09a3dbd8e -r d26c8a93d05a OrthancServer/OrthancHttpHandler.cpp --- a/OrthancServer/OrthancHttpHandler.cpp Wed Jul 01 12:09:58 2015 +0200 +++ b/OrthancServer/OrthancHttpHandler.cpp Wed Jul 01 12:30:19 2015 +0200 @@ -69,13 +69,20 @@ } - IHttpHandler& OrthancHttpHandler::GetOrthancRestApi() const + IHttpHandler& OrthancHttpHandler::RestrictToOrthancRestApi(bool restrict) { - if (orthancRestApi_ == NULL) + if (restrict) { - throw OrthancException(ErrorCode_InternalError); + if (orthancRestApi_ == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } + + return *orthancRestApi_; } - - return *orthancRestApi_; + else + { + return *this; + } } } diff -r b2b09a3dbd8e -r d26c8a93d05a OrthancServer/OrthancHttpHandler.h --- a/OrthancServer/OrthancHttpHandler.h Wed Jul 01 12:09:58 2015 +0200 +++ b/OrthancServer/OrthancHttpHandler.h Wed Jul 01 12:30:19 2015 +0200 @@ -64,6 +64,6 @@ return orthancRestApi_ != NULL; } - IHttpHandler& GetOrthancRestApi() const; + IHttpHandler& RestrictToOrthancRestApi(bool restrict); }; } diff -r b2b09a3dbd8e -r d26c8a93d05a Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Jul 01 12:09:58 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Jul 01 12:30:19 2015 +0200 @@ -616,38 +616,15 @@ const _OrthancPluginRestApiGet& p = *reinterpret_cast(parameters); - // TODO : Use "HttpToolbox::SimpleGet()" - - IHttpHandler::Arguments headers; // No HTTP header - std::string body; // No body for a GET request - - UriComponents uri; - IHttpHandler::GetArguments getArguments; - HttpToolbox::ParseGetQuery(uri, getArguments, p.uri); - - StringHttpOutput stream; - HttpOutput http(stream, false /* no keep alive */); - LOG(INFO) << "Plugin making REST GET call on URI " << p.uri << (afterPlugins ? " (after plugins)" : " (built-in API)"); - bool ok = false; - std::string result; - - if (afterPlugins) - { - ok = Handle(http, HttpMethod_Get, uri, headers, getArguments, body); - } + CheckContextAvailable(); + IHttpHandler& handler = pimpl_->context_->GetHttpHandler().RestrictToOrthancRestApi(!afterPlugins); - if (!ok) + std::string result; + if (HttpToolbox::SimpleGet(result, handler, p.uri)) { - ok = (pimpl_->restApi_ != NULL && - pimpl_->restApi_->Handle(http, HttpMethod_Get, uri, headers, getArguments, body)); - } - - if (ok) - { - stream.GetOutput(result); CopyToMemoryBuffer(*p.target, result); } else @@ -664,6 +641,8 @@ const _OrthancPluginRestApiPostPut& p = *reinterpret_cast(parameters); + // TODO : Use "HttpToolbox::SimplePost()" + IHttpHandler::Arguments headers; // No HTTP header IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT @@ -713,6 +692,8 @@ UriComponents uri; Toolbox::SplitUriComponents(uri, reinterpret_cast(parameters)); + // TODO : Use "HttpToolbox::SimpleDelete()" + IHttpHandler::Arguments headers; // No HTTP header IHttpHandler::GetArguments getArguments; // No GET argument for POST/PUT std::string body; // No body for DELETE