Handle redirections automatically

This commit is contained in:
Alex Spataru 2016-10-22 15:27:42 -05:00
parent a47c3b346e
commit fbb37ed225

View File

@ -200,9 +200,12 @@ void Downloader::onDownloadFinished() {
if (!data.isEmpty()) {
QString name = m_reply->url().toString().split ("/").last();
/* Handle HTML redirections automatically */
if (data.startsWith ("<html") || data.startsWith ("<!DOCTYPE html"))
name.append (".html");
/* Check if we need to redirect */
QUrl url = m_reply->attribute (QNetworkRequest::RedirectionTargetAttribute).toUrl();
if (!url.isEmpty()) {
startDownload (url);
return;
}
/* Save downloaded data to disk */
QFile file (QDir::tempPath() + "/" + name);