mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Network] Add a configured QNetworkAccessManager factory (#7628)
* [Network] Add a configured QNetworkAccessManager factory Every HTTP caller built its own QNetworkAccessManager, so the system proxy and a transfer timeout were easy to omit. Add NetworkManagerFactory::create() as the single place that applies the process-wide proxy configuration and a transfer timeout, and use it at all 14 construction sites. Per-site settings such as disk caches and manual redirect policies stay with their callers. * [Tests] Link libcockatrice_network into the tests that compile its headers release_channel.cpp and card_picture_loader_worker.cpp now include libcockatrice/network/network_manager.h, but the test targets that compile them only linked libcockatrice_settings, so the include directory never reached them and every platform failed with "file not found": loader_local_matching_test and picture_loader_benchmark_test. libcockatrice_network is an INTERFACE library, so linking it costs these targets nothing but hands over the include path. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
3b07b10b19
commit
518c7e6125
17 changed files with 69 additions and 20 deletions
|
|
@ -28,6 +28,7 @@
|
|||
#include <QVariant>
|
||||
#include <QtGlobal>
|
||||
#include <compare>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <libcockatrice/settings/cache_storage_settings.h>
|
||||
#include <libcockatrice/settings/download_settings.h>
|
||||
#include <libcockatrice/settings/paths_settings.h>
|
||||
|
|
@ -46,11 +47,10 @@ CardPictureLoaderWorker::CardPictureLoaderWorker()
|
|||
: QObject(nullptr), picDownload(SettingsCache::instance().downloads().getPicDownload()),
|
||||
hostRequestLimits(SettingsCache::instance().downloads().getHostRequestLimits())
|
||||
{
|
||||
networkManager = new QNetworkAccessManager(this);
|
||||
networkManager = NetworkManagerFactory::create(this);
|
||||
// We need a timeout to ensure requests don't hang indefinitely in case of
|
||||
// cache corruption, see related Qt bug: https://bugreports.qt.io/browse/QTBUG-111397
|
||||
// Use Qt's default timeout (30s, as of 2023-02-22)
|
||||
networkManager->setTransferTimeout();
|
||||
cache = new QNetworkDiskCache(this);
|
||||
cache->setCacheDirectory(SettingsCache::instance().getNetworkCachePath());
|
||||
cache->setMaximumCacheSize(1024L * 1024L *
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <QVBoxLayout>
|
||||
#include <functional>
|
||||
#include <libcockatrice/card/import/card_name_normalizer.h>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <qnamespace.h>
|
||||
#include <version_string.h>
|
||||
|
||||
|
|
@ -34,7 +35,7 @@ class QWidget;
|
|||
|
||||
DlgLoadDeckFromWebsite::DlgLoadDeckFromWebsite(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
nam = new QNetworkAccessManager(this);
|
||||
nam = NetworkManagerFactory::create(this);
|
||||
|
||||
layout = new QVBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
|
|
|||
|
|
@ -13,13 +13,14 @@
|
|||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
#include <QVariantMap>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <libcockatrice/settings/servers_settings.h>
|
||||
#include <qlogging.h>
|
||||
|
||||
#define PUBLIC_SERVERS_JSON "https://cockatrice.github.io/public-servers.json"
|
||||
|
||||
HandlePublicServers::HandlePublicServers(QObject *parent)
|
||||
: QObject(parent), nam(new QNetworkAccessManager(this)), reply(nullptr)
|
||||
: QObject(parent), nam(NetworkManagerFactory::create(this)), reply(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QSlider>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <qnamespace.h>
|
||||
|
||||
|
|
@ -27,8 +28,7 @@ ArchidektApiResponseDeckListingsDisplayWidget::ArchidektApiResponseDeckListingsD
|
|||
|
||||
cardSizeSlider->enableCtrlScrollResize(flowWidget);
|
||||
|
||||
imageNetworkManager = new QNetworkAccessManager(this);
|
||||
imageNetworkManager->setTransferTimeout(); // Use Qt's default timeout
|
||||
imageNetworkManager = NetworkManagerFactory::create(this);
|
||||
imageNetworkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||
|
||||
// Add widgets for deck listings
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
#include <QWidget>
|
||||
#include <QtGlobal>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <libcockatrice/settings/cards_display_settings.h>
|
||||
#include <libcockatrice/utility/qt_utils.h>
|
||||
#include <qlogging.h>
|
||||
|
|
@ -58,8 +59,7 @@ TabArchidekt::TabArchidekt(TabSupervisor *_tabSupervisor)
|
|||
: Tab(_tabSupervisor), currentPage(1), isLoadingMore(false), isListMode(true)
|
||||
{
|
||||
// Initialize network
|
||||
networkManager = new QNetworkAccessManager(this);
|
||||
networkManager->setTransferTimeout();
|
||||
networkManager = NetworkManagerFactory::create(this);
|
||||
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||
connect(networkManager, &QNetworkAccessManager::finished, this, &TabArchidekt::processApiJson);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@
|
|||
#include <QStringLiteral>
|
||||
#include <QUrl>
|
||||
#include <QVariant>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <libcockatrice/settings/commander_bracket_settings.h>
|
||||
|
||||
static const QUrl COMMANDER_BRACKET_JSON_URL(QStringLiteral("https://cockatrice.github.io/commander-brackets.json"));
|
||||
|
||||
HandleCommanderBrackets::HandleCommanderBrackets(QObject *parent)
|
||||
: QObject(parent), nam(new QNetworkAccessManager(this)), reply(nullptr)
|
||||
: QObject(parent), nam(NetworkManagerFactory::create(this)), reply(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,14 +18,14 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QSharedPointer>
|
||||
#include <QUrl>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <qlogging.h>
|
||||
|
||||
class TabSupervisor;
|
||||
|
||||
TabEdhRec::TabEdhRec(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor)
|
||||
{
|
||||
networkManager = new QNetworkAccessManager(this);
|
||||
networkManager->setTransferTimeout(); // Use Qt's default timeout
|
||||
networkManager = NetworkManagerFactory::create(this);
|
||||
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||
connect(networkManager, &QNetworkAccessManager::finished, this, &TabEdhRec::processApiJson);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <libcockatrice/models/database/card/card_search_model.h>
|
||||
#include <libcockatrice/models/database/card_database_display_model.h>
|
||||
#include <libcockatrice/models/database/card_database_model.h>
|
||||
#include <libcockatrice/network/network_manager.h>
|
||||
#include <libcockatrice/settings/cards_display_settings.h>
|
||||
#include <version_string.h>
|
||||
|
||||
|
|
@ -44,8 +45,7 @@ static bool canBeCommander(const CardInfoPtr &cardInfo)
|
|||
|
||||
TabEdhRecMain::TabEdhRecMain(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor)
|
||||
{
|
||||
networkManager = new QNetworkAccessManager(this);
|
||||
networkManager->setTransferTimeout(); // Use Qt's default timeout
|
||||
networkManager = NetworkManagerFactory::create(this);
|
||||
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processApiJson(QNetworkReply *)));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue