mirror of https://github.com/aria2/aria2
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.pull/230/merge
parent
84f1a15e10
commit
f60e55cece
|
@ -145,27 +145,33 @@ bool HttpRequestCommand::executeInternal() {
|
||||||
if(getOption()->getAsBool(PREF_CONDITIONAL_GET) &&
|
if(getOption()->getAsBool(PREF_CONDITIONAL_GET) &&
|
||||||
(getRequest()->getProtocol() == "http" ||
|
(getRequest()->getProtocol() == "http" ||
|
||||||
getRequest()->getProtocol() == "https")) {
|
getRequest()->getProtocol() == "https")) {
|
||||||
if(getFileEntry()->getPath().empty() &&
|
|
||||||
getRequest()->getFile().empty()) {
|
std::string path;
|
||||||
A2_LOG_DEBUG("Conditional-Get is disabled because file name"
|
|
||||||
" is not available.");
|
|
||||||
} else {
|
|
||||||
if(getFileEntry()->getPath().empty()) {
|
if(getFileEntry()->getPath().empty()) {
|
||||||
getFileEntry()->setPath
|
auto& file = getRequest()->getFile();
|
||||||
(util::createSafePath
|
|
||||||
|
// 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),
|
(getOption()->get(PREF_DIR),
|
||||||
util::percentDecode(getRequest()->getFile().begin(),
|
(getRequest()->getFile().empty() ?
|
||||||
getRequest()->getFile().end())));
|
Request::DEFAULT_FILE :
|
||||||
|
util::percentDecode(std::begin(file), std::end(file))));
|
||||||
|
} else {
|
||||||
|
path = getFileEntry()->getPath();
|
||||||
}
|
}
|
||||||
File ctrlfile(getFileEntry()->getPath()+
|
|
||||||
DefaultBtProgressInfoFile::getSuffix());
|
File ctrlfile(path + DefaultBtProgressInfoFile::getSuffix());
|
||||||
File file(getFileEntry()->getPath());
|
File file(path);
|
||||||
|
|
||||||
if(!ctrlfile.exists() && file.exists()) {
|
if(!ctrlfile.exists() && file.exists()) {
|
||||||
httpRequest->setIfModifiedSinceHeader
|
httpRequest->setIfModifiedSinceHeader
|
||||||
(file.getModifiedTime().toHTTPDate());
|
(file.getModifiedTime().toHTTPDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
httpConnection_->sendRequest(std::move(httpRequest));
|
httpConnection_->sendRequest(std::move(httpRequest));
|
||||||
} else {
|
} else {
|
||||||
for(auto& segment : getSegments()) {
|
for(auto& segment : getSegments()) {
|
||||||
|
|
|
@ -124,7 +124,7 @@ std::string HttpResponse::determineFilename() const
|
||||||
auto file = httpRequest_->getFile();
|
auto file = httpRequest_->getFile();
|
||||||
file = util::percentDecode(file.begin(), file.end());
|
file = util::percentDecode(file.begin(), file.end());
|
||||||
if (file.empty()) {
|
if (file.empty()) {
|
||||||
return "index.html";
|
return Request::DEFAULT_FILE;
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,8 @@ const std::string Request::METHOD_GET = "GET";
|
||||||
|
|
||||||
const std::string Request::METHOD_HEAD = "HEAD";
|
const std::string Request::METHOD_HEAD = "HEAD";
|
||||||
|
|
||||||
|
const std::string Request::DEFAULT_FILE = "index.html";
|
||||||
|
|
||||||
Request::Request():
|
Request::Request():
|
||||||
method_(METHOD_GET),
|
method_(METHOD_GET),
|
||||||
tryCount_(0),
|
tryCount_(0),
|
||||||
|
|
|
@ -220,6 +220,8 @@ public:
|
||||||
static const std::string METHOD_HEAD;
|
static const std::string METHOD_HEAD;
|
||||||
|
|
||||||
static const int MAX_REDIRECT = 20;
|
static const int MAX_REDIRECT = 20;
|
||||||
|
|
||||||
|
static const std::string DEFAULT_FILE;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue