mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [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>
38 lines
1.3 KiB
C++
38 lines
1.3 KiB
C++
#ifndef COCKATRICE_NETWORK_NETWORK_MANAGER_H
|
|
#define COCKATRICE_NETWORK_NETWORK_MANAGER_H
|
|
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkProxyFactory>
|
|
#include <mutex>
|
|
|
|
/**
|
|
* @file network_manager.h
|
|
* @ingroup Network
|
|
* @brief Creates QNetworkAccessManagers with the application-wide baseline.
|
|
*
|
|
* Every manager in the client should start from NetworkManagerFactory::create()
|
|
* so features that apply to all HTTP traffic (the system proxy, a transfer
|
|
* timeout) cannot be forgotten in one of the many call sites. Feature-specific
|
|
* setup such as a disk cache or a manual redirect policy stays with the caller.
|
|
*/
|
|
namespace NetworkManagerFactory
|
|
{
|
|
/**
|
|
* @brief Returns a QNetworkAccessManager configured for Cockatrice.
|
|
*
|
|
* The manager is parented to @p parent. The system proxy is enabled once,
|
|
* process-wide, the first time this function is called. Transfers use Qt's
|
|
* default timeout instead of waiting forever.
|
|
*/
|
|
inline QNetworkAccessManager *create(QObject *parent = nullptr)
|
|
{
|
|
static std::once_flag systemProxyFlag;
|
|
std::call_once(systemProxyFlag, [] { QNetworkProxyFactory::setUseSystemConfiguration(true); });
|
|
|
|
auto *manager = new QNetworkAccessManager(parent);
|
|
manager->setTransferTimeout();
|
|
return manager;
|
|
}
|
|
} // namespace NetworkManagerFactory
|
|
|
|
#endif // COCKATRICE_NETWORK_NETWORK_MANAGER_H
|