mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-19 04:02:09 +01:00
parent
0ce2cfd13c
commit
e5d566807a
@ -91,9 +91,14 @@ bool Downloader::doDownload(const Download &dl,
|
|||||||
{
|
{
|
||||||
QUrl url(dl.url());
|
QUrl url(dl.url());
|
||||||
|
|
||||||
|
if (!url.isValid() || !(url.scheme() == "http" || url.scheme() == "https")) {
|
||||||
|
qWarning("%s: Invalid URL\n", qPrintable(url.toString()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (_errorDownloads.contains(url))
|
if (_errorDownloads.contains(url))
|
||||||
return false;
|
return false;
|
||||||
if (_currentDownloads.contains(url))
|
if (_currentDownloads.contains(url) && !redirect)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QNetworkRequest request(url);
|
QNetworkRequest request(url);
|
||||||
@ -107,10 +112,12 @@ bool Downloader::doDownload(const Download &dl,
|
|||||||
request.setRawHeader("Authorization", authorization);
|
request.setRawHeader("Authorization", authorization);
|
||||||
|
|
||||||
QNetworkReply *reply = _manager.get(request);
|
QNetworkReply *reply = _manager.get(request);
|
||||||
if (reply) {
|
if (reply && reply->isRunning()) {
|
||||||
_currentDownloads.insert(url);
|
_currentDownloads.insert(url);
|
||||||
ReplyTimeout::setTimeout(reply, TIMEOUT);
|
ReplyTimeout::setTimeout(reply, TIMEOUT);
|
||||||
} else
|
} else if (reply)
|
||||||
|
downloadFinished(reply);
|
||||||
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -157,20 +164,25 @@ void Downloader::downloadFinished(QNetworkReply *reply)
|
|||||||
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
QUrl origin = reply->request().attribute(ATTR_ORIGIN).toUrl();
|
||||||
int level = reply->request().attribute(ATTR_LEVEL).toInt();
|
int level = reply->request().attribute(ATTR_LEVEL).toInt();
|
||||||
|
|
||||||
if (location == url) {
|
if (level >= MAX_REDIRECT_LEVEL) {
|
||||||
_errorDownloads.insert(url);
|
|
||||||
qWarning("Error downloading file: %s: "
|
|
||||||
"redirect loop\n", url.toEncoded().constData());
|
|
||||||
} else if (level >= MAX_REDIRECT_LEVEL) {
|
|
||||||
_errorDownloads.insert(origin);
|
_errorDownloads.insert(origin);
|
||||||
qWarning("Error downloading file: %s: "
|
qWarning("Error downloading file: %s: "
|
||||||
"redirect level limit reached\n",
|
"redirect level limit reached (redirect loop?)\n",
|
||||||
origin.toEncoded().constData());
|
origin.toEncoded().constData());
|
||||||
} else {
|
} else {
|
||||||
|
QUrl redirectUrl;
|
||||||
|
if (location.isRelative()) {
|
||||||
|
QString path = QDir::isAbsolutePath(location.path())
|
||||||
|
? location.path() : "/" + location.path();
|
||||||
|
redirectUrl = QUrl(url.scheme() + "://" + url.host() + path);
|
||||||
|
} else
|
||||||
|
redirectUrl = location;
|
||||||
|
|
||||||
Redirect redirect(origin.isEmpty() ? url : origin, level + 1);
|
Redirect redirect(origin.isEmpty() ? url : origin, level + 1);
|
||||||
Download dl(location, filename);
|
Download dl(redirectUrl, filename);
|
||||||
doDownload(dl, reply->request().rawHeader("Authorization"),
|
if (!doDownload(dl, reply->request().rawHeader("Authorization"),
|
||||||
&redirect);
|
&redirect))
|
||||||
|
_errorDownloads.insert(origin.isEmpty() ? url : origin);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
if (!saveToDisk(filename, reply))
|
if (!saveToDisk(filename, reply))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user