@@ -682,6 +682,20 @@ void ClientRequestDispatcher::handleIncomingMessage(SocketDisposition& dispositi
682
682
return ;
683
683
}
684
684
685
+ if (_postContentPending)
686
+ {
687
+ std::streamsize available = std::min<std::streamsize>(_postContentPending,
688
+ socket->getInBuffer ().size ());
689
+ _postStream.write (socket->getInBuffer ().data (), available);
690
+ socket->eraseFirstInputBytes (available);
691
+ _postContentPending -= available;
692
+ if (_postContentPending)
693
+ return ;
694
+ fprintf (stderr, " got everything written to %s\n " , _postFileDir.c_str ());
695
+ // TODO everything inside try catch basically as another block, then clean up after it
696
+ return ;
697
+ }
698
+
685
699
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now ();
686
700
std::chrono::duration<float , std::milli> delayMs = now - _lastSeenHTTPHeader;
687
701
@@ -708,6 +722,8 @@ void ClientRequestDispatcher::handleIncomingMessage(SocketDisposition& dispositi
708
722
return ;
709
723
}
710
724
725
+ assert (!_postStream.is_open () && _postFileDir.empty () && !_postContentPending);
726
+
711
727
// start streaming condition
712
728
bool streamToFile =
713
729
request.getMethod () == Poco::Net::HTTPRequest::HTTP_POST &&
@@ -716,14 +732,27 @@ void ClientRequestDispatcher::handleIncomingMessage(SocketDisposition& dispositi
716
732
717
733
fprintf (stderr, " CAN STREAM TO DISK %d\n " , streamToFile);
718
734
719
- #if 0
735
+ // do if we haven't enough in the first chunk
736
+ if (streamToFile)
720
737
{
721
- // Remove the request header from our input buffer
722
- socket->eraseFirstInputBytes(headerSize);
723
- ///:
724
- socket->eraseFirstInputBytes(map._messageSize - map._headerSize);
738
+ _postFileDir = FileUtil::createRandomTmpDir (COOLWSD::ChildRoot +
739
+ JailUtil::CHILDROOT_TMP_INCOMING_PATH) + ' /' ;
740
+ std::string postFilename = _postFileDir + " poststream" ;
741
+ _postStream.open (postFilename.c_str ());
742
+ if (!_postStream.good ())
743
+ {
744
+ LOG_ERR (" Unable to open [" << _postFileDir << " poststream] for POST streaming" );
745
+ FileUtil::removeFile (_postFileDir, true );
746
+ _postFileDir.clear ();
747
+ }
748
+ else
749
+ {
750
+ _postStream.write (socket->getInBuffer ().data (), headerSize);
751
+ socket->eraseFirstInputBytes (headerSize);
752
+ _postContentPending = request.getContentLength ();
753
+ return ;
754
+ }
725
755
}
726
- #endif
727
756
728
757
StreamSocket::MessageMap map;
729
758
if (!socket->parseHeader (" Client" , headerSize, socket->getInBuffer ().size (), request, delayMs, map))
0 commit comments