mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Add HTTP logging (#2991)
Co-authored-by: Paweł <zneix@zneix.eu> Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
parent
b8bd0a587d
commit
f949d6d154
|
@ -11,6 +11,7 @@
|
||||||
- Bugfix: Fixed comma appended to username completion when not at the beginning of the message. (#3060)
|
- Bugfix: Fixed comma appended to username completion when not at the beginning of the message. (#3060)
|
||||||
- Dev: Ubuntu packages are now available (#2936)
|
- Dev: Ubuntu packages are now available (#2936)
|
||||||
- Dev: Disabled update checker on Flatpak. (#3051)
|
- Dev: Disabled update checker on Flatpak. (#3051)
|
||||||
|
- Dev: Add logging for HTTP requests (#2991)
|
||||||
|
|
||||||
## 2.3.3
|
## 2.3.3
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,13 @@ enum class NetworkRequestType {
|
||||||
Delete,
|
Delete,
|
||||||
Patch,
|
Patch,
|
||||||
};
|
};
|
||||||
|
const static std::vector<QString> networkRequestTypes{
|
||||||
|
"GET", //
|
||||||
|
"POST", //
|
||||||
|
"PUT", //
|
||||||
|
"DELETE", //
|
||||||
|
"PATCH", //
|
||||||
|
};
|
||||||
|
|
||||||
// parseHeaderList takes a list of headers in string form,
|
// parseHeaderList takes a list of headers in string form,
|
||||||
// where each header pair is separated by semicolons (;) and the header name and value is divided by a colon (:)
|
// where each header pair is separated by semicolons (;) and the header name and value is divided by a colon (:)
|
||||||
|
|
|
@ -145,6 +145,11 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
||||||
data->timer_, &QTimer::timeout, worker, [reply, data]() {
|
data->timer_, &QTimer::timeout, worker, [reply, data]() {
|
||||||
qCDebug(chatterinoCommon) << "Aborted!";
|
qCDebug(chatterinoCommon) << "Aborted!";
|
||||||
reply->abort();
|
reply->abort();
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 [timed out] %2")
|
||||||
|
.arg(networkRequestTypes.at(
|
||||||
|
int(data->requestType_)),
|
||||||
|
data->request_.url().toString());
|
||||||
|
|
||||||
if (data->onError_)
|
if (data->onError_)
|
||||||
{
|
{
|
||||||
|
@ -181,6 +186,11 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
||||||
QNetworkReply::NetworkError::OperationCanceledError)
|
QNetworkReply::NetworkError::OperationCanceledError)
|
||||||
{
|
{
|
||||||
// Operation cancelled, most likely timed out
|
// Operation cancelled, most likely timed out
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 [cancelled] %2")
|
||||||
|
.arg(networkRequestTypes.at(
|
||||||
|
int(data->requestType_)),
|
||||||
|
data->request_.url().toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +198,25 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
||||||
{
|
{
|
||||||
auto status = reply->attribute(
|
auto status = reply->attribute(
|
||||||
QNetworkRequest::HttpStatusCodeAttribute);
|
QNetworkRequest::HttpStatusCodeAttribute);
|
||||||
|
if (data->requestType_ == NetworkRequestType::Get)
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 %2 %3")
|
||||||
|
.arg(networkRequestTypes.at(
|
||||||
|
int(data->requestType_)),
|
||||||
|
QString::number(status.toInt()),
|
||||||
|
data->request_.url().toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 %2 %3 %4")
|
||||||
|
.arg(networkRequestTypes.at(
|
||||||
|
int(data->requestType_)),
|
||||||
|
QString::number(status.toInt()),
|
||||||
|
data->request_.url().toString(),
|
||||||
|
QString(data->payload_));
|
||||||
|
}
|
||||||
// TODO: Should this always be run on the GUI thread?
|
// TODO: Should this always be run on the GUI thread?
|
||||||
postToThread([data, code = status.toInt()] {
|
postToThread([data, code = status.toInt()] {
|
||||||
data->onError_(NetworkResult({}, code));
|
data->onError_(NetworkResult({}, code));
|
||||||
|
@ -227,6 +256,23 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (data->requestType_ == NetworkRequestType::Get)
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 %2 %3")
|
||||||
|
.arg(networkRequestTypes.at(int(data->requestType_)),
|
||||||
|
QString::number(status.toInt()),
|
||||||
|
data->request_.url().toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 %3 %2 %4")
|
||||||
|
.arg(networkRequestTypes.at(int(data->requestType_)),
|
||||||
|
data->request_.url().toString(),
|
||||||
|
QString::number(status.toInt()),
|
||||||
|
QString(data->payload_));
|
||||||
|
}
|
||||||
if (data->finally_)
|
if (data->finally_)
|
||||||
{
|
{
|
||||||
if (data->executeConcurrently_)
|
if (data->executeConcurrently_)
|
||||||
|
@ -286,6 +332,10 @@ void loadCached(const std::shared_ptr<NetworkData> &data)
|
||||||
QByteArray bytes = cachedFile.readAll();
|
QByteArray bytes = cachedFile.readAll();
|
||||||
NetworkResult result(bytes, 200);
|
NetworkResult result(bytes, 200);
|
||||||
|
|
||||||
|
qCDebug(chatterinoHTTP)
|
||||||
|
<< QString("%1 [CACHED] 200 %2")
|
||||||
|
.arg(networkRequestTypes.at(int(data->requestType_)),
|
||||||
|
data->request_.url().toString());
|
||||||
if (data->onSuccess_)
|
if (data->onSuccess_)
|
||||||
{
|
{
|
||||||
if (data->executeConcurrently_ || isGuiThread())
|
if (data->executeConcurrently_ || isGuiThread())
|
||||||
|
|
|
@ -15,6 +15,7 @@ Q_LOGGING_CATEGORY(chatterinoCommon, "chatterino.common", logThreshold);
|
||||||
Q_LOGGING_CATEGORY(chatterinoEmoji, "chatterino.emoji", logThreshold);
|
Q_LOGGING_CATEGORY(chatterinoEmoji, "chatterino.emoji", logThreshold);
|
||||||
Q_LOGGING_CATEGORY(chatterinoFfzemotes, "chatterino.ffzemotes", logThreshold);
|
Q_LOGGING_CATEGORY(chatterinoFfzemotes, "chatterino.ffzemotes", logThreshold);
|
||||||
Q_LOGGING_CATEGORY(chatterinoHelper, "chatterino.helper", logThreshold);
|
Q_LOGGING_CATEGORY(chatterinoHelper, "chatterino.helper", logThreshold);
|
||||||
|
Q_LOGGING_CATEGORY(chatterinoHTTP, "chatterino.http", logThreshold);
|
||||||
Q_LOGGING_CATEGORY(chatterinoImage, "chatterino.image", logThreshold);
|
Q_LOGGING_CATEGORY(chatterinoImage, "chatterino.image", logThreshold);
|
||||||
Q_LOGGING_CATEGORY(chatterinoIrc, "chatterino.irc", logThreshold);
|
Q_LOGGING_CATEGORY(chatterinoIrc, "chatterino.irc", logThreshold);
|
||||||
Q_LOGGING_CATEGORY(chatterinoIvr, "chatterino.ivr", logThreshold);
|
Q_LOGGING_CATEGORY(chatterinoIvr, "chatterino.ivr", logThreshold);
|
||||||
|
|
|
@ -11,6 +11,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoCommon);
|
||||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoEmoji);
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoEmoji);
|
||||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoFfzemotes);
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoFfzemotes);
|
||||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoHelper);
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoHelper);
|
||||||
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoHTTP);
|
||||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoImage);
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoImage);
|
||||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoIrc);
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoIrc);
|
||||||
Q_DECLARE_LOGGING_CATEGORY(chatterinoIvr);
|
Q_DECLARE_LOGGING_CATEGORY(chatterinoIvr);
|
||||||
|
|
Loading…
Reference in a new issue