Mercurial > hg > orthanc
comparison Core/HttpServer/HttpServer.cpp @ 3357:c0aa5f1cf2f5
new class: FileBuffer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 02 May 2019 09:22:36 +0200 |
parents | f744730c294b |
children | 0ce9b4f5fdf5 |
comparison
equal
deleted
inserted
replaced
3356:f744730c294b | 3357:c0aa5f1cf2f5 |
---|---|
34 // http://en.highscore.de/cpp/boost/stringhandling.html | 34 // http://en.highscore.de/cpp/boost/stringhandling.html |
35 | 35 |
36 #include "../PrecompiledHeaders.h" | 36 #include "../PrecompiledHeaders.h" |
37 #include "HttpServer.h" | 37 #include "HttpServer.h" |
38 | 38 |
39 #include "../ChunkedBuffer.h" | |
40 #include "../FileBuffer.h" | |
39 #include "../Logging.h" | 41 #include "../Logging.h" |
40 #include "../ChunkedBuffer.h" | |
41 #include "../OrthancException.h" | 42 #include "../OrthancException.h" |
43 #include "../TemporaryFile.h" | |
42 #include "HttpToolbox.h" | 44 #include "HttpToolbox.h" |
43 | 45 |
44 #if ORTHANC_ENABLE_MONGOOSE == 1 | 46 #if ORTHANC_ENABLE_MONGOOSE == 1 |
45 # include <mongoose.h> | 47 # include <mongoose.h> |
46 | 48 |
306 const IHttpHandler::Arguments& headers) | 308 const IHttpHandler::Arguments& headers) |
307 { | 309 { |
308 IHttpHandler::Arguments::const_iterator cs = headers.find("content-length"); | 310 IHttpHandler::Arguments::const_iterator cs = headers.find("content-length"); |
309 if (cs == headers.end()) | 311 if (cs == headers.end()) |
310 { | 312 { |
311 // TODO - Avoid storing this entirely in RAM, use temporary | 313 // Store all the individual chunks within a temporary file, then |
312 // files instead. The amount of RAM needed to receive one body | 314 // read it back into the memory buffer "postData" |
313 // of "N" bytes is currently "2*N" bytes (one copy in "buffer", | 315 FileBuffer buffer; |
314 // one copy in "postData"). With a | 316 |
315 // "ChunkedBufferInTemporaryFiles", one would need "N" bytes (in | |
316 // "postData" only). | |
317 | |
318 std::string tmp(1024 * 1024, 0); | 317 std::string tmp(1024 * 1024, 0); |
319 | 318 |
320 ChunkedBuffer buffer; | |
321 | |
322 for (;;) | 319 for (;;) |
323 { | 320 { |
324 int r = mg_read(connection, &tmp[0], tmp.size()); | 321 int r = mg_read(connection, &tmp[0], tmp.size()); |
325 if (r < 0) | 322 if (r < 0) |
326 { | 323 { |
330 { | 327 { |
331 break; | 328 break; |
332 } | 329 } |
333 else | 330 else |
334 { | 331 { |
335 buffer.AddChunk(tmp.c_str(), r); | 332 buffer.Append(tmp.c_str(), r); |
336 } | 333 } |
337 } | 334 } |
338 | 335 |
339 buffer.Flatten(postData); | 336 buffer.Read(postData); |
340 | 337 |
341 return PostDataStatus_Success; | 338 return PostDataStatus_Success; |
342 } | 339 } |
343 else | 340 else |
344 { | 341 { |
342 // "Content-Length" is available | |
345 int length; | 343 int length; |
346 try | 344 try |
347 { | 345 { |
348 length = boost::lexical_cast<int>(cs->second); | 346 length = boost::lexical_cast<int>(cs->second); |
349 } | 347 } |