From 906215317ac105d6dce718d9faf4b045637f923e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 16 Jul 2010 14:13:04 +0000 Subject: 2010-07-16 Tatsuhiro Tsujikawa Added --conditional-get option. Download file only when the local file is older than remote file. This function only works with HTTP(S) downloads only. It does not work if file size is specified in Metalink. It also ignores Content-Disposition header. If a control file exists, this option will be ignored. This function uses If-Modified-Since header to get only newer file conditionally. When getting modification time of local file, it uses user supplied filename(see --out option) or filename part in URI if --out is not specified. * doc/aria2c.1.txt * src/HttpHeader.cc * src/HttpHeader.h * src/HttpRequest.cc * src/HttpRequest.h * src/HttpRequestCommand.cc * src/HttpResponse.cc * src/HttpResponseCommand.cc * src/OptionHandlerFactory.cc * src/TimeA2.cc * src/TimeA2.h * src/prefs.cc * src/prefs.h * src/usage_text.h * test/HttpResponseTest.cc * test/TimeTest.cc --- src/HttpResponseCommand.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/HttpResponseCommand.cc') diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index b523699a..3a24a97d 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -119,7 +119,26 @@ bool HttpResponseCommand::executeInternal() (getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING)); } - if(httpResponse->getResponseStatus() >= HttpHeader::S300) { + if(!httpResponse->getHttpRequest()->getIfModifiedSinceHeader().empty()) { + if(httpResponse->getResponseStatus() == HttpHeader::S304) { + uint64_t totalLength = httpResponse->getEntityLength(); + getFileEntry()->setLength(totalLength); + getRequestGroup()->initPieceStorage(); + getPieceStorage()->markAllPiecesDone(); + getLogger()->notice(MSG_DOWNLOAD_ALREADY_COMPLETED, + util::itos(getRequestGroup()->getGID()).c_str(), + getRequestGroup()->getFirstFilePath().c_str()); + poolConnection(); + getFileEntry()->poolRequest(getRequest()); + return true; + } else if(httpResponse->getResponseStatus() == HttpHeader::S200 || + httpResponse->getResponseStatus() == HttpHeader::S206) { + // Remote file is newer than local file. We allow overwrite. + getOption()->put(PREF_ALLOW_OVERWRITE, V_TRUE); + } + } + if(httpResponse->getResponseStatus() >= HttpHeader::S300 && + httpResponse->getResponseStatus() != HttpHeader::S304) { if(httpResponse->getResponseStatus() == HttpHeader::S404) { getRequestGroup()->increaseAndValidateFileNotFoundCount(); } -- cgit