From 9742032dcdc0e72c117ae0c589fbb59452d6d33c Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 29 Jun 2020 12:23:02 +0200 Subject: http: Finish copying data from server to file before sending stuff to server This avoids a case where we read data, then write to the server and only then realize the connection was closed. It is somewhat slower, though. --- methods/http.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'methods') diff --git a/methods/http.cc b/methods/http.cc index 40a37a8c6..161ecf067 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -846,13 +846,6 @@ ResultState HttpServerState::Go(bool ToFile, RequestState &Req) return Die(Req); } - if (ServerFd->Fd() != -1 && FD_ISSET(ServerFd->Fd(), &wfds)) - { - errno = 0; - if (Out.Write(ServerFd) == false) - return Die(Req); - } - // Send data to the file if (FileFD->Fd() != -1 && FD_ISSET(FileFD->Fd(), &wfds)) { @@ -863,6 +856,13 @@ ResultState HttpServerState::Go(bool ToFile, RequestState &Req) } } + if (ServerFd->Fd() != -1 && FD_ISSET(ServerFd->Fd(), &wfds)) + { + errno = 0; + if (Out.Write(ServerFd) == false) + return Die(Req); + } + if (Req.MaximumSize > 0 && Req.File.IsOpen() && Req.File.Failed() == false && Req.File.Tell() > Req.MaximumSize) { Owner->SetFailReason("MaximumSizeExceeded"); -- cgit v1.2.3