mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Set our own custom User-Agent on network requests.
Format: chatterino/VERSION (COMMIT HASH) Fixes #1169
This commit is contained in:
parent
e7d9422431
commit
45e2887ce8
3 changed files with 33 additions and 0 deletions
|
@ -446,3 +446,20 @@ linux {
|
||||||
|
|
||||||
INSTALLS += desktop build_icons icon target
|
INSTALLS += desktop build_icons icon target
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git_commit=$$(GIT_COMMIT)
|
||||||
|
git_release=$$(GIT_RELEASE)
|
||||||
|
# Git data
|
||||||
|
isEmpty(git_commit) {
|
||||||
|
git_commit=$$system(git rev-parse HEAD)
|
||||||
|
}
|
||||||
|
isEmpty(git_release) {
|
||||||
|
git_release=$$system(git describe)
|
||||||
|
}
|
||||||
|
git_hash = $$str_member($$git_commit, 0, 8)
|
||||||
|
|
||||||
|
# Passing strings as defines requires you to use this weird triple-escape then quotation mark syntax.
|
||||||
|
# https://stackoverflow.com/questions/3348711/add-a-define-to-qmake-with-a-value/18343449#18343449
|
||||||
|
DEFINES += CHATTERINO_GIT_COMMIT=\\\"$$git_commit\\\"
|
||||||
|
DEFINES += CHATTERINO_GIT_RELEASE=\\\"$$git_release\\\"
|
||||||
|
DEFINES += CHATTERINO_GIT_HASH=\\\"$$git_hash\\\"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "common/NetworkData.hpp"
|
#include "common/NetworkData.hpp"
|
||||||
#include "common/NetworkManager.hpp"
|
#include "common/NetworkManager.hpp"
|
||||||
#include "common/Outcome.hpp"
|
#include "common/Outcome.hpp"
|
||||||
|
#include "common/Version.hpp"
|
||||||
#include "debug/Log.hpp"
|
#include "debug/Log.hpp"
|
||||||
#include "providers/twitch/TwitchCommon.hpp"
|
#include "providers/twitch/TwitchCommon.hpp"
|
||||||
#include "singletons/Paths.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->request_.setUrl(QUrl(QString::fromStdString(url)));
|
||||||
this->data->requestType_ = requestType;
|
this->data->requestType_ = requestType;
|
||||||
|
|
||||||
|
this->initializeDefaultValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest::NetworkRequest(QUrl url, NetworkRequestType requestType)
|
NetworkRequest::NetworkRequest(QUrl url, NetworkRequestType requestType)
|
||||||
|
@ -30,6 +33,8 @@ NetworkRequest::NetworkRequest(QUrl url, NetworkRequestType requestType)
|
||||||
{
|
{
|
||||||
this->data->request_.setUrl(url);
|
this->data->request_.setUrl(url);
|
||||||
this->data->requestType_ = requestType;
|
this->data->requestType_ = requestType;
|
||||||
|
|
||||||
|
this->initializeDefaultValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRequest::~NetworkRequest()
|
NetworkRequest::~NetworkRequest()
|
||||||
|
@ -166,6 +171,15 @@ QString NetworkRequest::urlString() const
|
||||||
return this->data->request_.url().toString();
|
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()
|
Outcome NetworkRequest::tryLoadCachedFile()
|
||||||
{
|
{
|
||||||
QFile cachedFile(getPaths()->cacheDirectory() + "/" +
|
QFile cachedFile(getPaths()->cacheDirectory() + "/" +
|
||||||
|
|
|
@ -60,6 +60,8 @@ public:
|
||||||
QString urlString() const;
|
QString urlString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void initializeDefaultValues();
|
||||||
|
|
||||||
// "invalid" data "invalid" is specified by the onSuccess callback
|
// "invalid" data "invalid" is specified by the onSuccess callback
|
||||||
Outcome tryLoadCachedFile();
|
Outcome tryLoadCachedFile();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue