Set user agent

This commit is contained in:
Tobias Fella 2020-07-02 19:14:07 +02:00
parent 2c4effe372
commit 237a6d67ed
2 changed files with 9 additions and 2 deletions

View File

@ -46,7 +46,7 @@ void Fetcher::fetch(QString url)
Q_EMIT startedFetchingFeed(url);
QNetworkRequest request((QUrl(url)));
QNetworkReply *reply = manager->get(request);
QNetworkReply *reply = get(request);
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
QByteArray data = reply->readAll();
Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url);
@ -183,7 +183,7 @@ QString Fetcher::image(QString url)
void Fetcher::download(QString url)
{
QNetworkRequest request((QUrl(url)));
QNetworkReply *reply = manager->get(request);
QNetworkReply *reply = get(request);
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
QByteArray data = reply->readAll();
QFile file(filePath(url));
@ -205,3 +205,9 @@ QString Fetcher::filePath(QString url)
{
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/") + QString::fromStdString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex().toStdString());
}
QNetworkReply *Fetcher::get(QNetworkRequest &request)
{
request.setRawHeader("User-Agent", "Alligator/0.1; Syndication");
return manager->get(request);
}

View File

@ -39,6 +39,7 @@ public:
Q_INVOKABLE QString image(QString);
void removeImage(QString);
Q_INVOKABLE void download(QString url);
QNetworkReply *get(QNetworkRequest &request);
private:
Fetcher();