Skip to content

Commit 1c23eba

Browse files
committed
interim
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com> Change-Id: I14291b443d57ca2bada3d55d991b4cc9fd30c5fd
1 parent 53bba98 commit 1c23eba

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

wsd/ClientRequestDispatcher.cpp

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,20 @@ void ClientRequestDispatcher::handleIncomingMessage(SocketDisposition& dispositi
682682
return;
683683
}
684684

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+
685699
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
686700
std::chrono::duration<float, std::milli> delayMs = now - _lastSeenHTTPHeader;
687701

@@ -708,6 +722,8 @@ void ClientRequestDispatcher::handleIncomingMessage(SocketDisposition& dispositi
708722
return;
709723
}
710724

725+
assert(!_postStream.is_open() && _postFileDir.empty() && !_postContentPending);
726+
711727
// start streaming condition
712728
bool streamToFile =
713729
request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST &&
@@ -716,14 +732,27 @@ void ClientRequestDispatcher::handleIncomingMessage(SocketDisposition& dispositi
716732

717733
fprintf(stderr, "CAN STREAM TO DISK %d\n", streamToFile);
718734

719-
#if 0
735+
// do if we haven't enough in the first chunk
736+
if (streamToFile)
720737
{
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+
}
725755
}
726-
#endif
727756

728757
StreamSocket::MessageMap map;
729758
if (!socket->parseHeader("Client", headerSize, socket->getInBuffer().size(), request, delayMs, map))

wsd/ClientRequestDispatcher.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class ClientRequestDispatcher final : public SimpleSocketHandler
152152
/// WS is created and as long as it is connected.
153153
std::shared_ptr<RequestVettingStation> _rvs;
154154

155+
/// scratch dir that POSTs are streamed to
156+
std::string _postFileDir;
157+
std::fstream _postStream;
158+
std::streamsize _postContentPending;
159+
155160
/// The minimum number of RVS instances in flight to trigger cleanup.
156161
static constexpr std::size_t RvsLowWatermark = 1 * 1024;
157162

0 commit comments

Comments
 (0)