Skip to content

Commit

Permalink
PropCond: Added HTTP Header User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Feb 14, 2025
1 parent e6b9256 commit b6983f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 17 additions & 7 deletions core/PropConditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

MODULE_IDENTIFICATION("qlog.core.conditions");

PropConditions::PropConditions(QObject *parent) : QObject(parent)
PropConditions::PropConditions(QObject *parent) : QObject(parent),
agentString(QString("QLog/%1").arg(VERSION).toUtf8())
{
FCT_IDENTIFICATION;

Expand All @@ -62,10 +63,10 @@ void PropConditions::update()
{
FCT_IDENTIFICATION;

nam->get(QNetworkRequest(QUrl(SOLAR_SUMMARY_IMG)));
nam->get(QNetworkRequest(QUrl(K_INDEX_URL)));
nam->get(QNetworkRequest(QUrl(AURORA_MAP)));
nam->get(QNetworkRequest(QUrl(MUF_POINTS)));
nam->get(prepareRequest(QUrl(SOLAR_SUMMARY_IMG)));
nam->get(prepareRequest(QUrl(K_INDEX_URL)));
nam->get(prepareRequest(QUrl(AURORA_MAP)));
nam->get(prepareRequest(QUrl(MUF_POINTS)));
}

void PropConditions::updateDxTrends()
Expand All @@ -75,7 +76,7 @@ void PropConditions::updateDxTrends()
dxTrendResult.clear();

for ( const QString& continent : Data::getContinentList() )
dxTrendPendingConnections << nam->get(QNetworkRequest(QUrl(DXC_TRENDS + QString("/%0/15").arg(continent))));
dxTrendPendingConnections << nam->get(prepareRequest(QUrl(DXC_TRENDS + QString("/%0/15").arg(continent))));

dxTrendTimeoutTimer.start(DXTRENDS_TIMEOUT * 1000);
}
Expand Down Expand Up @@ -265,7 +266,7 @@ void PropConditions::repeateRequest(const QUrl &url)
QTimer::singleShot(1000 * RESEND_BASE_INTERVAL * failedRequests[url], this, [this, url]()
{
qCDebug(runtime) << "Resending request" << url.toString();
nam->get(QNetworkRequest(url));
nam->get(prepareRequest(url));
});
}
else
Expand All @@ -274,6 +275,15 @@ void PropConditions::repeateRequest(const QUrl &url)
}
}

QNetworkRequest PropConditions::prepareRequest(const QUrl &url)
{
FCT_IDENTIFICATION;

QNetworkRequest req(url);
req.setRawHeader("User-Agent", agentString);
return req;
}

void PropConditions::dxTrendTimeout()
{
FCT_IDENTIFICATION;
Expand Down
4 changes: 3 additions & 1 deletion core/PropConditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class QNetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;

template<class T>
class GenericValueMap
Expand Down Expand Up @@ -106,8 +107,9 @@ public slots:
QList<QNetworkReply *> dxTrendPendingConnections;
QTimer dxTrendTimeoutTimer;
QHash<QString, QHash<QString, QHash<QString, int>>> dxTrendResult;

QByteArray agentString;
void repeateRequest(const QUrl &);
QNetworkRequest prepareRequest(const QUrl &);

private slots:
void dxTrendTimeout();
Expand Down

0 comments on commit b6983f3

Please sign in to comment.