Mercurial > hg > orthanc
diff Plugins/Engine/OrthancPlugins.cpp @ 1445:d26c8a93d05a
refactoring: SimpleGet
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 12:30:19 +0200 |
parents | f3672356c121 |
children | 8dc80ba768aa |
line wrap: on
line diff
--- 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<const _OrthancPluginRestApiGet*>(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<const _OrthancPluginRestApiPostPut*>(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<const char*>(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