From beb1c6dbf2cf80a6db1bcb6729d989f77dca0b15 Mon Sep 17 00:00:00 2001 From: vkamn Date: Wed, 20 Aug 2025 13:00:35 +0800 Subject: [PATCH] feat: added cache for proxy bypass (#1797) --- client/core/controllers/gatewayController.cpp | 23 ++++++++++++++++--- client/core/controllers/gatewayController.h | 2 ++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/client/core/controllers/gatewayController.cpp b/client/core/controllers/gatewayController.cpp index 26855ae6..ade5979b 100644 --- a/client/core/controllers/gatewayController.cpp +++ b/client/core/controllers/gatewayController.cpp @@ -344,11 +344,14 @@ void GatewayController::bypassProxy(const QString &endpoint, QNetworkReply *repl std::mt19937 generator(randomDevice()); std::shuffle(proxyUrls.begin(), proxyUrls.end(), generator); - QEventLoop wait; - QList sslErrors; QByteArray responseBody; - for (const QString &proxyUrl : proxyUrls) { + auto bypassFunction = [this](const QString &endpoint, const QString &proxyUrl, QNetworkReply *reply, + std::function requestFunction, + std::function &sslErrors)> replyProcessingFunction) { + QEventLoop wait; + QList sslErrors; + qDebug() << "go to the next proxy endpoint"; reply->deleteLater(); // delete the previous reply reply = requestFunction(endpoint.arg(proxyUrl)); @@ -358,6 +361,20 @@ void GatewayController::bypassProxy(const QString &endpoint, QNetworkReply *repl wait.exec(); if (replyProcessingFunction(reply, sslErrors)) { + return true; + } + return false; + }; + + if (!m_proxyUrl.isEmpty()) { + if (bypassFunction(endpoint, m_proxyUrl, reply, requestFunction, replyProcessingFunction)) { + return; + } + } + + for (const QString &proxyUrl : proxyUrls) { + if (bypassFunction(endpoint, proxyUrl, reply, requestFunction, replyProcessingFunction)) { + m_proxyUrl = proxyUrl; break; } } diff --git a/client/core/controllers/gatewayController.h b/client/core/controllers/gatewayController.h index 9f91df53..4c247fc6 100644 --- a/client/core/controllers/gatewayController.h +++ b/client/core/controllers/gatewayController.h @@ -32,6 +32,8 @@ private: QString m_gatewayEndpoint; bool m_isDevEnvironment = false; bool m_isStrictKillSwitchEnabled = false; + + inline static QString m_proxyUrl; }; #endif // GATEWAYCONTROLLER_H