# HG changeset patch # User Sebastien Jodogne # Date 1556551470 -7200 # Node ID f744730c294b5f5608dd95889815069484b28e0c # Parent e60e194531e5c72bb5e7788c8a8ce6e8b877f7a5 Orthanc now accepts chunked transfer encoding diff -r e60e194531e5 -r f744730c294b Core/HttpServer/HttpServer.cpp --- a/Core/HttpServer/HttpServer.cpp Tue Apr 23 22:56:17 2019 +0200 +++ b/Core/HttpServer/HttpServer.cpp Mon Apr 29 17:24:30 2019 +0200 @@ -308,41 +308,73 @@ IHttpHandler::Arguments::const_iterator cs = headers.find("content-length"); if (cs == headers.end()) { - return PostDataStatus_NoLength; - } - - int length; - try - { - length = boost::lexical_cast(cs->second); - } - catch (boost::bad_lexical_cast&) - { - return PostDataStatus_NoLength; - } + // TODO - Avoid storing this entirely in RAM, use temporary + // files instead. The amount of RAM needed to receive one body + // of "N" bytes is currently "2*N" bytes (one copy in "buffer", + // one copy in "postData"). With a + // "ChunkedBufferInTemporaryFiles", one would need "N" bytes (in + // "postData" only). + + std::string tmp(1024 * 1024, 0); + + ChunkedBuffer buffer; - if (length < 0) - { - length = 0; - } - - postData.resize(length); - - size_t pos = 0; - while (length > 0) - { - int r = mg_read(connection, &postData[pos], length); - if (r <= 0) + for (;;) { - return PostDataStatus_Failure; + int r = mg_read(connection, &tmp[0], tmp.size()); + if (r < 0) + { + return PostDataStatus_Failure; + } + else if (r == 0) + { + break; + } + else + { + buffer.AddChunk(tmp.c_str(), r); + } } - assert(r <= length); - length -= r; - pos += r; + buffer.Flatten(postData); + + return PostDataStatus_Success; } + else + { + int length; + try + { + length = boost::lexical_cast(cs->second); + } + catch (boost::bad_lexical_cast&) + { + return PostDataStatus_NoLength; + } - return PostDataStatus_Success; + if (length < 0) + { + length = 0; + } + + postData.resize(length); + + size_t pos = 0; + while (length > 0) + { + int r = mg_read(connection, &postData[pos], length); + if (r <= 0) + { + return PostDataStatus_Failure; + } + + assert(r <= length); + length -= r; + pos += r; + } + + return PostDataStatus_Success; + } } diff -r e60e194531e5 -r f744730c294b NEWS --- a/NEWS Tue Apr 23 22:56:17 2019 +0200 +++ b/NEWS Mon Apr 29 17:24:30 2019 +0200 @@ -5,6 +5,7 @@ Maintenance ----------- +* Orthanc now accepts "-H 'Transfer-Encoding: chunked'" option from curl * Size of the Orthanc static binaries are reduced by compressing ICU data * Anonymization: Preserve hierarchical relationships in (0008,1115) [] (0020,000e) * Fix issue #136 (C-FIND request fails when found DICOM file does not have certain tags)