Set our own custom User-Agent on network requests.

Format: chatterino/VERSION (COMMIT HASH)

Fixes #1169
This commit is contained in:
Rasmus Karlsson
2019-08-03 11:20:19 +02:00
parent e7d9422431
commit 45e2887ce8
3 changed files with 33 additions and 0 deletions
+14
View File
@@ -3,6 +3,7 @@
#include "common/NetworkData.hpp"
#include "common/NetworkManager.hpp"
#include "common/Outcome.hpp"
#include "common/Version.hpp"
#include "debug/Log.hpp"
#include "providers/twitch/TwitchCommon.hpp"
#include "singletons/Paths.hpp"
@@ -22,6 +23,8 @@ NetworkRequest::NetworkRequest(const std::string &url,
{
this->data->request_.setUrl(QUrl(QString::fromStdString(url)));
this->data->requestType_ = requestType;
this->initializeDefaultValues();
}
NetworkRequest::NetworkRequest(QUrl url, NetworkRequestType requestType)
@@ -30,6 +33,8 @@ NetworkRequest::NetworkRequest(QUrl url, NetworkRequestType requestType)
{
this->data->request_.setUrl(url);
this->data->requestType_ = requestType;
this->initializeDefaultValues();
}
NetworkRequest::~NetworkRequest()
@@ -166,6 +171,15 @@ QString NetworkRequest::urlString() const
return this->data->request_.url().toString();
}
void NetworkRequest::initializeDefaultValues()
{
const auto userAgent = QString("chatterino/%1 (%2)")
.arg(CHATTERINO_VERSION, CHATTERINO_GIT_HASH)
.toUtf8();
this->data->request_.setRawHeader("User-Agent", userAgent);
}
Outcome NetworkRequest::tryLoadCachedFile()
{
QFile cachedFile(getPaths()->cacheDirectory() + "/" +