From d7518dba50e2285c41c7002a1d86f876401fd9ea Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 24 Jul 2017 14:30:41 +0200 Subject: fail earlier if server answers with too much data We tend to operate on rather large static files, which means we usually get Content-Length information from the server. If we combine this information with the filesize we are expecting (factoring in pipelining) we can avoid reading a bunch of data we are ending up rejecting anyhow by just closing the connection saving bandwidth and time both for the server as well as the client. --- methods/http.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'methods/http.cc') diff --git a/methods/http.cc b/methods/http.cc index 9f01d15b3..9425145dd 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -267,6 +267,7 @@ bool CircleBuf::Write(string &Data) OutP += LeftWrite(); return true; } + /*}}}*/ // CircleBuf::Stats - Print out stats information /*{{{*/ // --------------------------------------------------------------------- /* */ @@ -282,11 +283,12 @@ void CircleBuf::Stats() clog << "Got " << InP << " in " << Diff << " at " << InP/Diff << endl;*/ } /*}}}*/ -CircleBuf::~CircleBuf() +CircleBuf::~CircleBuf() /*{{{*/ { delete [] Buf; delete Hash; } + /*}}}*/ // UnwrapHTTPConnect - Does the HTTP CONNECT handshake /*{{{*/ // --------------------------------------------------------------------- @@ -590,7 +592,15 @@ bool HttpServerState::RunData(RequestState &Req) if (Req.JunkSize != 0) In.Limit(Req.JunkSize); else if (Req.DownloadSize != 0) + { + if (Req.MaximumSize != 0 && Req.DownloadSize > Req.MaximumSize) + { + Owner->SetFailReason("MaximumSizeExceeded"); + return _error->Error(_("File is larger than expected (%llu > %llu). Mirror sync in progress?"), + Req.DownloadSize, Req.MaximumSize); + } In.Limit(Req.DownloadSize); + } else if (Persistent == false) In.Limit(-1); @@ -827,8 +837,8 @@ bool HttpServerState::Go(bool ToFile, RequestState &Req) if (Req.MaximumSize > 0 && Req.File.IsOpen() && Req.File.Failed() == false && Req.File.Tell() > Req.MaximumSize) { Owner->SetFailReason("MaximumSizeExceeded"); - return _error->Error("Writing more data than expected (%llu > %llu)", - Req.File.Tell(), Req.MaximumSize); + return _error->Error(_("File is larger than expected (%llu > %llu). Mirror sync in progress?"), + Req.File.Tell(), Req.MaximumSize); } // Handle commands from APT -- cgit v1.2.3