From 237a6d67ed1938244afaa2a12ea8a1fa64eae7d0 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Thu, 2 Jul 2020 19:14:07 +0200 Subject: [PATCH] Set user agent --- src/fetcher.cpp | 10 ++++++++-- src/fetcher.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fetcher.cpp b/src/fetcher.cpp index ac860dbe..1e6fb8c4 100644 --- a/src/fetcher.cpp +++ b/src/fetcher.cpp @@ -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); +} diff --git a/src/fetcher.h b/src/fetcher.h index a442131f..3909f741 100644 --- a/src/fetcher.h +++ b/src/fetcher.h @@ -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();