NOISSUE Always follow redirects for NetAction based downloads
This commit is contained in:
parent
a060d79c12
commit
bbcd44a657
@ -286,7 +286,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
|
auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
|
||||||
auto action = CacheDownload::make(
|
auto action = CacheDownload::make(
|
||||||
QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
|
QUrl("http://" + URLConstants::SKINS_BASE + profile.name + ".png"), meta);
|
||||||
action->m_followRedirects = true;
|
|
||||||
skin_dls.append(action);
|
skin_dls.append(action);
|
||||||
meta->stale = true;
|
meta->stale = true;
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,6 @@ void LegacyJarModPage::on_addForgeBtn_clicked()
|
|||||||
{
|
{
|
||||||
NetJob *fjob = new NetJob("Forge download");
|
NetJob *fjob = new NetJob("Forge download");
|
||||||
auto cacheDl = CacheDownload::make(forge->universal_url, entry);
|
auto cacheDl = CacheDownload::make(forge->universal_url, entry);
|
||||||
cacheDl->m_followRedirects = true;
|
|
||||||
fjob->addNetAction(cacheDl);
|
fjob->addNetAction(cacheDl);
|
||||||
ProgressDialog dlg(this);
|
ProgressDialog dlg(this);
|
||||||
dlg.exec(fjob);
|
dlg.exec(fjob);
|
||||||
|
@ -58,28 +58,25 @@ void ByteArrayDownload::downloadError(QNetworkReply::NetworkError error)
|
|||||||
|
|
||||||
void ByteArrayDownload::downloadFinished()
|
void ByteArrayDownload::downloadFinished()
|
||||||
{
|
{
|
||||||
if (m_followRedirects)
|
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
||||||
|
QString redirectURL;
|
||||||
|
if(redirect.isValid())
|
||||||
{
|
{
|
||||||
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
redirectURL = redirect.toString();
|
||||||
QString redirectURL;
|
}
|
||||||
if(redirect.isValid())
|
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
||||||
{
|
else if(m_reply->hasRawHeader("Location"))
|
||||||
redirectURL = redirect.toString();
|
{
|
||||||
}
|
auto data = m_reply->rawHeader("Location");
|
||||||
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
if(data.size() > 2 && data[0] == '/' && data[1] == '/')
|
||||||
else if(m_reply->hasRawHeader("Location"))
|
redirectURL = m_reply->url().scheme() + ":" + data;
|
||||||
{
|
}
|
||||||
auto data = m_reply->rawHeader("Location");
|
if (!redirectURL.isEmpty())
|
||||||
if(data.size() > 2 && data[0] == '/' && data[1] == '/')
|
{
|
||||||
redirectURL = m_reply->url().scheme() + ":" + data;
|
m_url = QUrl(redirect.toString());
|
||||||
}
|
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
||||||
if (!redirectURL.isEmpty())
|
start();
|
||||||
{
|
return;
|
||||||
m_url = QUrl(redirect.toString());
|
|
||||||
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
|
||||||
start();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the download succeeded
|
// if the download succeeded
|
||||||
|
@ -33,8 +33,6 @@ public:
|
|||||||
|
|
||||||
QString m_errorString;
|
QString m_errorString;
|
||||||
|
|
||||||
bool m_followRedirects = false;
|
|
||||||
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
virtual void start();
|
virtual void start();
|
||||||
|
@ -101,28 +101,25 @@ void CacheDownload::downloadError(QNetworkReply::NetworkError error)
|
|||||||
}
|
}
|
||||||
void CacheDownload::downloadFinished()
|
void CacheDownload::downloadFinished()
|
||||||
{
|
{
|
||||||
if (m_followRedirects)
|
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
||||||
|
QString redirectURL;
|
||||||
|
if(redirect.isValid())
|
||||||
{
|
{
|
||||||
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
|
redirectURL = redirect.toString();
|
||||||
QString redirectURL;
|
}
|
||||||
if(redirect.isValid())
|
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
||||||
{
|
else if(m_reply->hasRawHeader("Location"))
|
||||||
redirectURL = redirect.toString();
|
{
|
||||||
}
|
auto data = m_reply->rawHeader("Location");
|
||||||
// FIXME: This is a hack for https://bugreports.qt-project.org/browse/QTBUG-41061
|
if(data.size() > 2 && data[0] == '/' && data[1] == '/')
|
||||||
else if(m_reply->hasRawHeader("Location"))
|
redirectURL = m_reply->url().scheme() + ":" + data;
|
||||||
{
|
}
|
||||||
auto data = m_reply->rawHeader("Location");
|
if (!redirectURL.isEmpty())
|
||||||
if(data.size() > 2 && data[0] == '/' && data[1] == '/')
|
{
|
||||||
redirectURL = m_reply->url().scheme() + ":" + data;
|
m_url = QUrl(redirect.toString());
|
||||||
}
|
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
||||||
if (!redirectURL.isEmpty())
|
start();
|
||||||
{
|
return;
|
||||||
m_url = QUrl(redirect.toString());
|
|
||||||
QLOG_INFO() << "Following redirect to " << m_url.toString();
|
|
||||||
start();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the download succeeded
|
// if the download succeeded
|
||||||
|
@ -36,8 +36,6 @@ private:
|
|||||||
bool wroteAnyData = false;
|
bool wroteAnyData = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool m_followRedirects = false;
|
|
||||||
|
|
||||||
explicit CacheDownload(QUrl url, MetaEntryPtr entry);
|
explicit CacheDownload(QUrl url, MetaEntryPtr entry);
|
||||||
static CacheDownloadPtr make(QUrl url, MetaEntryPtr entry)
|
static CacheDownloadPtr make(QUrl url, MetaEntryPtr entry)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user