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