From f60e55cece6eeee5357b68557ba8ddd4f8051b74 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 8 May 2014 21:41:32 +0900 Subject: [PATCH] Use index.html as filename for conditional-get when file is missing in URI Previously we disabled conditional-get if file part is missing in URI. But we use constant string "index.html" in this case, so we can do the same to determine the modification time. In this patch, if we have file part in URI, we are not going to set absolute file path in FileEntry, since it prevents content-disposition from working. --- src/HttpRequestCommand.cc | 42 ++++++++++++++++++++++----------------- src/HttpResponse.cc | 2 +- src/Request.cc | 2 ++ src/Request.h | 2 ++ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc index c92d2a4f..1b3f4072 100644 --- a/src/HttpRequestCommand.cc +++ b/src/HttpRequestCommand.cc @@ -145,25 +145,31 @@ bool HttpRequestCommand::executeInternal() { if(getOption()->getAsBool(PREF_CONDITIONAL_GET) && (getRequest()->getProtocol() == "http" || getRequest()->getProtocol() == "https")) { - if(getFileEntry()->getPath().empty() && - getRequest()->getFile().empty()) { - A2_LOG_DEBUG("Conditional-Get is disabled because file name" - " is not available."); + + std::string path; + + if(getFileEntry()->getPath().empty()) { + auto& file = getRequest()->getFile(); + + // If filename part of URI is empty, we just use + // Request::DEFAULT_FILE, since it is the name we use to + // store file in disk. + + path = util::createSafePath + (getOption()->get(PREF_DIR), + (getRequest()->getFile().empty() ? + Request::DEFAULT_FILE : + util::percentDecode(std::begin(file), std::end(file)))); } else { - if(getFileEntry()->getPath().empty()) { - getFileEntry()->setPath - (util::createSafePath - (getOption()->get(PREF_DIR), - util::percentDecode(getRequest()->getFile().begin(), - getRequest()->getFile().end()))); - } - File ctrlfile(getFileEntry()->getPath()+ - DefaultBtProgressInfoFile::getSuffix()); - File file(getFileEntry()->getPath()); - if(!ctrlfile.exists() && file.exists()) { - httpRequest->setIfModifiedSinceHeader - (file.getModifiedTime().toHTTPDate()); - } + path = getFileEntry()->getPath(); + } + + File ctrlfile(path + DefaultBtProgressInfoFile::getSuffix()); + File file(path); + + if(!ctrlfile.exists() && file.exists()) { + httpRequest->setIfModifiedSinceHeader + (file.getModifiedTime().toHTTPDate()); } } httpConnection_->sendRequest(std::move(httpRequest)); diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index c4168b3e..80c1cfd6 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -124,7 +124,7 @@ std::string HttpResponse::determineFilename() const auto file = httpRequest_->getFile(); file = util::percentDecode(file.begin(), file.end()); if (file.empty()) { - return "index.html"; + return Request::DEFAULT_FILE; } return file; } diff --git a/src/Request.cc b/src/Request.cc index 09890c1f..0520e5f0 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -50,6 +50,8 @@ const std::string Request::METHOD_GET = "GET"; const std::string Request::METHOD_HEAD = "HEAD"; +const std::string Request::DEFAULT_FILE = "index.html"; + Request::Request(): method_(METHOD_GET), tryCount_(0), diff --git a/src/Request.h b/src/Request.h index 1dc62617..92619199 100644 --- a/src/Request.h +++ b/src/Request.h @@ -220,6 +220,8 @@ public: static const std::string METHOD_HEAD; static const int MAX_REDIRECT = 20; + + static const std::string DEFAULT_FILE; }; } // namespace aria2