# HG changeset patch # User Alain Mazy # Date 1665673903 -7200 # Node ID d842e4446e63dfa499eed76120a9bbb476c534e5 # Parent 1faae6dc282f1dc4195d6670ded0f0861ebc3d55 Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB) diff -r 1faae6dc282f -r d842e4446e63 NEWS --- a/NEWS Thu Oct 13 17:11:12 2022 +0200 +++ b/NEWS Thu Oct 13 17:11:43 2022 +0200 @@ -19,6 +19,7 @@ Users should be careful to preserve the DICOM model when modifying high level tags. E.g. if you modify the PatientID at study level, also make sure to modify all other Patient related tags (PatientName, PatientBirthDate, ...) +* Allow the HTTP server to return responses > 2GB (fixes asynchronous download of zip studies > 2GB) OrthancFramework (C++) diff -r 1faae6dc282f -r d842e4446e63 OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Thu Oct 13 17:11:12 2022 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Thu Oct 13 17:11:43 2022 +0200 @@ -35,6 +35,7 @@ #include "IHttpHandler.h" #include "MultipartStreamReader.h" #include "StringHttpOutput.h" +#include #if ORTHANC_ENABLE_PUGIXML == 1 # include "IWebDavBucket.h" @@ -109,12 +110,25 @@ { if (length > 0) { - int status = mg_write(connection_, buffer, length); - if (status != static_cast(length)) + // mg_write does not support buffers > 2GB (INT_MAX) -> need to split it + size_t offset = 0; + size_t remainingSize = length; + + while (remainingSize > 0) { - // status == 0 when the connection has been closed, -1 on error - throw OrthancException(ErrorCode_NetworkProtocol); - } + size_t packetSize = std::min(remainingSize, static_cast(INT_MAX)); + + int status = mg_write(connection_, &(reinterpret_cast(buffer)[offset]), packetSize); + + if (status != static_cast(packetSize)) + { + // status == 0 when the connection has been closed, -1 on error + throw OrthancException(ErrorCode_NetworkProtocol); + } + + offset += packetSize; + remainingSize -= packetSize; + } } }