mirror of
https://github.com/transmission/transmission
synced 2025-02-22 14:10:34 +00:00
feat: add 'TR_RPC_VERBOSE' env variable in Qt app. (#1435)
When set, this will log the RPC messages sent between the GUI and the backend. This replaces the old `#ifdef DEBUG_HTTP` as something that can be enabled without needing to recompile.
This commit is contained in:
parent
542feef77d
commit
bda60c5a18
1 changed files with 20 additions and 18 deletions
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
#include "VariantHelpers.h"
|
#include "VariantHelpers.h"
|
||||||
|
|
||||||
// #define DEBUG_HTTP
|
|
||||||
|
|
||||||
using ::trqt::variant_helpers::dictAdd;
|
using ::trqt::variant_helpers::dictAdd;
|
||||||
using ::trqt::variant_helpers::dictFind;
|
using ::trqt::variant_helpers::dictFind;
|
||||||
using ::trqt::variant_helpers::variantInit;
|
using ::trqt::variant_helpers::variantInit;
|
||||||
|
@ -36,6 +34,8 @@ namespace
|
||||||
char const constexpr* const RequestDataPropertyKey { "requestData" };
|
char const constexpr* const RequestDataPropertyKey { "requestData" };
|
||||||
char const constexpr* const RequestFutureinterfacePropertyKey { "requestReplyFutureInterface" };
|
char const constexpr* const RequestFutureinterfacePropertyKey { "requestReplyFutureInterface" };
|
||||||
|
|
||||||
|
bool const Verbose = tr_env_key_exists("TR_RPC_VERBOSE");
|
||||||
|
|
||||||
void destroyVariant(tr_variant* json)
|
void destroyVariant(tr_variant* json)
|
||||||
{
|
{
|
||||||
tr_variantFree(json);
|
tr_variantFree(json);
|
||||||
|
@ -155,16 +155,17 @@ void RpcClient::sendNetworkRequest(TrVariantPtr json, QFutureInterface<RpcRespon
|
||||||
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(dataReadProgress()));
|
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(dataReadProgress()));
|
||||||
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SIGNAL(dataSendProgress()));
|
connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SIGNAL(dataSendProgress()));
|
||||||
|
|
||||||
#ifdef DEBUG_HTTP
|
if (Verbose)
|
||||||
std::cerr << "sending " << "POST " << qPrintable(url_.path()) << std::endl;
|
|
||||||
|
|
||||||
for (QByteArray const& b : request.rawHeaderList())
|
|
||||||
{
|
{
|
||||||
std::cerr << b.constData() << ": " << request.rawHeader(b).constData() << std::endl;
|
std::cerr << "sending " << "POST " << qPrintable(url_.path()) << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "Body:\n" << json_data.constData() << std::endl;
|
for (QByteArray const& b : request_->rawHeaderList())
|
||||||
#endif
|
{
|
||||||
|
std::cerr << b.constData() << ": " << request_->rawHeader(b).constData() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "Body:\n" << json_data.constData() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RpcClient::sendLocalRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise, int64_t tag)
|
void RpcClient::sendLocalRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise, int64_t tag)
|
||||||
|
@ -233,16 +234,17 @@ void RpcClient::networkRequestFinished(QNetworkReply* reply)
|
||||||
auto promise = reply->property(RequestFutureinterfacePropertyKey).
|
auto promise = reply->property(RequestFutureinterfacePropertyKey).
|
||||||
value<QFutureInterface<RpcResponse>>();
|
value<QFutureInterface<RpcResponse>>();
|
||||||
|
|
||||||
#ifdef DEBUG_HTTP
|
if (Verbose)
|
||||||
std::cerr << "http response header: " << std::endl;
|
|
||||||
|
|
||||||
for (QByteArray const& b : reply->rawHeaderList())
|
|
||||||
{
|
{
|
||||||
std::cerr << b.constData() << ": " << reply->rawHeader(b).constData() << std::endl;
|
std::cerr << "http response header: " << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << "json:\n" << reply->peek(reply->bytesAvailable()).constData() << std::endl;
|
for (QByteArray const& b : reply->rawHeaderList())
|
||||||
#endif
|
{
|
||||||
|
std::cerr << b.constData() << ": " << reply->rawHeader(b).constData() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "json:\n" << reply->peek(reply->bytesAvailable()).constData() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 409 &&
|
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 409 &&
|
||||||
reply->hasRawHeader(TR_RPC_SESSION_ID_HEADER))
|
reply->hasRawHeader(TR_RPC_SESSION_ID_HEADER))
|
||||||
|
|
Loading…
Reference in a new issue