fix: Add check for Content-Type when downloading tracker list.

Check if the URL from where we are downloading the trackers returns `Content-Type` as `text`.
Otherwise consider it might be a non-usable format for this functionality (html,xml,etc.ect.)
This commit is contained in:
Stiliyan Tonev (Bark) 2025-01-10 09:56:21 +02:00
commit 67db0c03d7
3 changed files with 9 additions and 0 deletions

View file

@ -143,6 +143,7 @@ void Net::DownloadHandlerImpl::processFinishedDownload()
#else
m_result.data = m_reply->readAll();
#endif
m_result.contentType = m_reply->header(QNetworkRequest::ContentTypeHeader).toString();
if (m_downloadRequest.saveToFile())
{

View file

@ -107,6 +107,7 @@ namespace Net
QByteArray data;
Path filePath;
QString magnetURI;
QString contentType;
};
class DownloadHandler : public QObject

View file

@ -109,6 +109,13 @@ void TrackersAdditionDialog::onTorrentListDownloadFinished(const Net::DownloadRe
m_ui->downloadButton->setEnabled(true);
setCursor(Qt::ArrowCursor);
if (!result.contentType.contains(u"text/plain"_s, Qt::CaseInsensitive))
{
QMessageBox::warning(this, tr("Download trackers list error")
, tr("The content type of the downloaded file is not plain text. Content-Type: \"%1\"").arg(result.contentType));
return;
}
if (result.status != Net::DownloadStatus::Success)
{
QMessageBox::warning(this, tr("Download trackers list error")