mirror of https://github.com/KDE/kasts.git
Set user agent
This commit is contained in:
parent
2c4effe372
commit
237a6d67ed
|
@ -46,7 +46,7 @@ void Fetcher::fetch(QString url)
|
||||||
Q_EMIT startedFetchingFeed(url);
|
Q_EMIT startedFetchingFeed(url);
|
||||||
|
|
||||||
QNetworkRequest request((QUrl(url)));
|
QNetworkRequest request((QUrl(url)));
|
||||||
QNetworkReply *reply = manager->get(request);
|
QNetworkReply *reply = get(request);
|
||||||
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
|
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url);
|
Syndication::DocumentSource *document = new Syndication::DocumentSource(data, url);
|
||||||
|
@ -183,7 +183,7 @@ QString Fetcher::image(QString url)
|
||||||
void Fetcher::download(QString url)
|
void Fetcher::download(QString url)
|
||||||
{
|
{
|
||||||
QNetworkRequest request((QUrl(url)));
|
QNetworkRequest request((QUrl(url)));
|
||||||
QNetworkReply *reply = manager->get(request);
|
QNetworkReply *reply = get(request);
|
||||||
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
|
connect(reply, &QNetworkReply::finished, this, [this, url, reply]() {
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
QFile file(filePath(url));
|
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());
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
Q_INVOKABLE QString image(QString);
|
Q_INVOKABLE QString image(QString);
|
||||||
void removeImage(QString);
|
void removeImage(QString);
|
||||||
Q_INVOKABLE void download(QString url);
|
Q_INVOKABLE void download(QString url);
|
||||||
|
QNetworkReply *get(QNetworkRequest &request);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Fetcher();
|
Fetcher();
|
||||||
|
|
Loading…
Reference in New Issue