Mercurial > hg > orthanc
changeset 6231:c13cc738bceb
make OrthancPluginCallRestApi() return the body of DELETE requests
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Jul 2025 18:52:19 +0200 |
parents | b8660d8ff4e7 |
children | 46cd2a84ffdf |
files | NEWS OrthancFramework/Sources/HttpServer/HttpToolbox.cpp OrthancFramework/Sources/HttpServer/IHttpHandler.cpp OrthancFramework/Sources/HttpServer/IHttpHandler.h OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Sources/LuaScripting.cpp |
diffstat | 6 files changed, 16 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Tue Jul 08 11:41:27 2025 +0200 +++ b/NEWS Tue Jul 08 18:52:19 2025 +0200 @@ -31,6 +31,8 @@ DICOM resource from a plugin. - "OrthancPluginRedirectNotAuthenticatedToRoot()" to allow a plugin to redirect unauthenticated users to a login page. +* OrthancPluginCallRestApi() now also returns the body of DELETE requests: + https://discourse.orthanc-server.org/t/response-to-plugin-from-orthanc-api-delete-endpoint/6022 Plugins -------
--- a/OrthancFramework/Sources/HttpServer/HttpToolbox.cpp Tue Jul 08 11:41:27 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpToolbox.cpp Tue Jul 08 18:52:19 2025 +0200 @@ -230,7 +230,8 @@ const std::string& uri, const Arguments& httpHeaders) { - return (IHttpHandler::SimpleDelete(NULL, handler, origin, uri, httpHeaders) == HttpStatus_200_Ok); + std::string ignoredBody; + return (IHttpHandler::SimpleDelete(ignoredBody, NULL, handler, origin, uri, httpHeaders) == HttpStatus_200_Ok); } #endif }
--- a/OrthancFramework/Sources/HttpServer/IHttpHandler.cpp Tue Jul 08 11:41:27 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/IHttpHandler.cpp Tue Jul 08 18:52:19 2025 +0200 @@ -133,7 +133,8 @@ } - HttpStatus IHttpHandler::SimpleDelete(HttpToolbox::Arguments* answerHeaders, + HttpStatus IHttpHandler::SimpleDelete(std::string& answerBody, + HttpToolbox::Arguments* answerHeaders, IHttpHandler& handler, RequestOrigin origin, const std::string& uri, @@ -150,6 +151,8 @@ if (handler.Handle(http, origin, LOCALHOST, "", HttpMethod_Delete, curi, httpHeaders, getArguments, NULL /* no body for DELETE */, 0)) { + stream.GetBody(answerBody); + if (answerHeaders != NULL) { stream.GetHeaders(*answerHeaders, true /* convert key to lower case */);
--- a/OrthancFramework/Sources/HttpServer/IHttpHandler.h Tue Jul 08 11:41:27 2025 +0200 +++ b/OrthancFramework/Sources/HttpServer/IHttpHandler.h Tue Jul 08 18:52:19 2025 +0200 @@ -116,7 +116,8 @@ size_t bodySize, const HttpToolbox::Arguments& httpHeaders); - static HttpStatus SimpleDelete(HttpToolbox::Arguments* answerHeaders /* out */, + static HttpStatus SimpleDelete(std::string& answerBody /* out */, + HttpToolbox::Arguments* answerHeaders /* out */, IHttpHandler& handler, RequestOrigin origin, const std::string& uri,
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Tue Jul 08 11:41:27 2025 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp Tue Jul 08 18:52:19 2025 +0200 @@ -3387,7 +3387,8 @@ std::map<std::string, std::string> httpHeaders; - ThrowOnHttpError(IHttpHandler::SimpleDelete(NULL, *handler, RequestOrigin_Plugins, uri, httpHeaders)); + std::string bodyIgnored; + ThrowOnHttpError(IHttpHandler::SimpleDelete(bodyIgnored, NULL, *handler, RequestOrigin_Plugins, uri, httpHeaders)); } @@ -4176,7 +4177,7 @@ case OrthancPluginHttpMethod_Delete: status = IHttpHandler::SimpleDelete( - &answerHeaders, *handler, RequestOrigin_Plugins, p.uri, headers); + answerBody, &answerHeaders, *handler, RequestOrigin_Plugins, p.uri, headers); break; default: @@ -4192,8 +4193,7 @@ } PluginMemoryBuffer32 tmpBody; - if (p.method != OrthancPluginHttpMethod_Delete && - p.answerBody != NULL) + if (p.answerBody != NULL) { tmpBody.Assign(answerBody); }
--- a/OrthancServer/Sources/LuaScripting.cpp Tue Jul 08 11:41:27 2025 +0200 +++ b/OrthancServer/Sources/LuaScripting.cpp Tue Jul 08 18:52:19 2025 +0200 @@ -552,7 +552,8 @@ try { - if (IHttpHandler::SimpleDelete(NULL, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), + std::string bodyIgnored; + if (IHttpHandler::SimpleDelete(bodyIgnored, NULL, serverContext->GetHttpHandler().RestrictToOrthancRestApi(builtin), RequestOrigin_Lua, uri, headers) == HttpStatus_200_Ok) { lua_pushboolean(state, 1);