Mercurial > hg > orthanc
diff Plugins/Engine/OrthancPlugins.cpp @ 1447:5ba7471780ae
refactoring: HttpToolbox, DumpJson in Lua
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Jul 2015 17:42:06 +0200 |
parents | 8dc80ba768aa |
children | b737acb13da5 |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Wed Jul 01 13:16:12 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed Jul 01 17:42:06 2015 +0200 @@ -642,38 +642,17 @@ 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 + LOG(INFO) << "Plugin making REST " << EnumerationToString(isPost ? HttpMethod_Post : HttpMethod_Put) + << " call on URI " << p.uri << (afterPlugins ? " (after plugins)" : " (built-in API)"); - UriComponents uri; - Toolbox::SplitUriComponents(uri, p.uri); - - StringHttpOutput stream; - HttpOutput http(stream, false /* no keep alive */); - - HttpMethod method = (isPost ? HttpMethod_Post : HttpMethod_Put); - LOG(INFO) << "Plugin making REST " << EnumerationToString(method) << " call on URI " << p.uri - << (afterPlugins ? " (after plugins)" : " (built-in API)"); + CheckContextAvailable(); + IHttpHandler& handler = pimpl_->context_->GetHttpHandler().RestrictToOrthancRestApi(!afterPlugins); - bool ok = false; std::string result; - - if (afterPlugins) + if (isPost ? + HttpToolbox::SimplePost(result, handler, p.uri, p.body, p.bodySize) : + HttpToolbox::SimplePut (result, handler, p.uri, p.body, p.bodySize)) { - ok = Handle(http, method, uri, headers, getArguments, p.body, p.bodySize); - } - - if (!ok) - { - ok = (pimpl_->restApi_ != NULL && - pimpl_->restApi_->Handle(http, method, uri, headers, getArguments, p.body, p.bodySize)); - } - - if (ok) - { - stream.GetOutput(result); CopyToMemoryBuffer(*p.target, result); } else @@ -686,38 +665,14 @@ void OrthancPlugins::RestApiDelete(const void* parameters, bool afterPlugins) { - // The "parameters" point to the URI - 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 - - StringHttpOutput stream; - HttpOutput http(stream, false /* no keep alive */); - - LOG(INFO) << "Plugin making REST DELETE call on URI " - << reinterpret_cast<const char*>(parameters) + const char* uri = reinterpret_cast<const char*>(parameters); + LOG(INFO) << "Plugin making REST DELETE call on URI " << uri << (afterPlugins ? " (after plugins)" : " (built-in API)"); - bool ok = false; - - if (afterPlugins) - { - ok = Handle(http, HttpMethod_Delete, uri, headers, getArguments, - NULL /* no body for DELETE */, 0); - } + CheckContextAvailable(); + IHttpHandler& handler = pimpl_->context_->GetHttpHandler().RestrictToOrthancRestApi(!afterPlugins); - if (!ok) - { - ok = (pimpl_->restApi_ != NULL && - pimpl_->restApi_->Handle(http, HttpMethod_Delete, uri, headers, getArguments, - NULL /* no body for DELETE */, 0)); - } - - if (!ok) + if (!HttpToolbox::SimpleDelete(handler, uri)) { throw OrthancException(ErrorCode_BadRequest); }