# HG changeset patch # User Alain Mazy # Date 1770882734 -3600 # Node ID 56eb61c86f9300e0a6559b18cda8b8ca3bae9c0a # Parent 63cf1a09fa9058acd1257c32ba78a0e8ec825ca5 refactor diff -r 63cf1a09fa90 -r 56eb61c86f93 OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp --- a/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Feb 12 08:45:35 2026 +0100 +++ b/OrthancServer/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Thu Feb 12 08:52:14 2026 +0100 @@ -1544,11 +1544,25 @@ #endif /* HAS_ORTHANC_PLUGIN_FIND_MATCHER == 1 */ + void CheckAnswerSizeIsLessThan4GB(const std::string& answer) + { + if (answer.size() > static_cast(std::numeric_limits::max())) + { + #if HAS_ORTHANC_EXCEPTION == 1 + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, "Cannot send HTTP response larger than 4GB"); + #else + ORTHANC_PLUGINS_LOG_ERROR("Cannot send HTTP response larger than 4GB"); + ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); + #endif + } + } + void AnswerJson(const Json::Value& value, OrthancPluginRestOutput* output) { std::string bodyString; - WriteStyledJson(bodyString, value); + WriteStyledJson(bodyString, value); + CheckAnswerSizeIsLessThan4GB(bodyString); OrthancPluginAnswerBuffer(GetGlobalContext(), output, bodyString.c_str(), bodyString.size(), "application/json"); } @@ -1556,6 +1570,7 @@ const char* mimeType, OrthancPluginRestOutput* output) { + CheckAnswerSizeIsLessThan4GB(answer); OrthancPluginAnswerBuffer(GetGlobalContext(), output, answer.c_str(), answer.size(), mimeType); } @@ -1569,15 +1584,7 @@ const std::string& answer, const char* mimeType) { - if (answer.size() > static_cast(std::numeric_limits::max())) - { - #if HAS_ORTHANC_EXCEPTION == 1 - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, "Cannot send HTTP response larger than 4GB"); - #else - ORTHANC_PLUGINS_LOG_ERROR("Cannot send HTTP response larger than 4GB"); - ORTHANC_PLUGINS_THROW_PLUGIN_ERROR_CODE(OrthancPluginErrorCode_ParameterOutOfRange); - #endif - } + CheckAnswerSizeIsLessThan4GB(answer); OrthancPluginSetHttpHeader(GetGlobalContext(), output,