-
Notifications
You must be signed in to change notification settings - Fork 13
/
proxyhandler.cpp
51 lines (44 loc) · 1.43 KB
/
proxyhandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "proxyhandler.hpp"
void ProxyHandler::printCurrentProxySettings()
{
if (QNetworkProxyFactory::usesSystemConfiguration())
{
qDebug() << "Using system proxy configuration.";
}
else
{
qDebug() << "Using custom proxy configuration.";
}
QNetworkProxy proxy = QNetworkProxy::applicationProxy();
qDebug() << "Proxy type:" << proxy.type();
qDebug() << "Proxy host:" << proxy.hostName();
qDebug() << "Proxy port:" << proxy.port();
qDebug() << "Proxy user:" << proxy.user();
qDebug() << "Proxy password:" << proxy.password();
}
Q_INVOKABLE void ProxyHandler::useSystemProxy()
{
QByteArray proxyUrl = qgetenv("https_proxy");
qDebug() << "Proxy URL: " << proxyUrl;
if (!proxyUrl.isEmpty())
{
QUrl url{QString(proxyUrl)};
qDebug() << "Proxy URL is not empty: " << url;
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::HttpProxy);
proxy.setHostName(url.host());
proxy.setPort(url.port());
if (!url.userName().isEmpty())
{
proxy.setUser(url.userName());
}
if (!url.password().isEmpty())
{
proxy.setPassword(url.password());
}
qDebug() << "Proxy: " << proxy;
QNetworkProxy::setApplicationProxy(proxy);
}
qDebug() << "application proxy is" << QNetworkProxy::applicationProxy();
qDebug() << "Done setting use system proxy to true";
}