Skip to content

Commit 9911084

Browse files
arthursdootavio
authored andcommitted
proxyHandler:Add ProxyHandler for Authenticated Proxy Support
Added ProxyHandler class to qt-kiosk-browser for handling proxies with login authentication, automatically configured using https_proxy and http_proxy environment variables. This enhancement simplifies connectivity in environments with secure proxy requirements. Signed-off-by: Arthur Oliveira <[email protected]>
1 parent fadca6c commit 9911084

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

browser.pro

+2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ CONFIG += c++11
77
TARGET = qt-kiosk-browser
88

99
HEADERS += \
10+
proxyhandler.hpp \
1011
inputeventhandler.hpp \
1112
browser.hpp
1213

1314
SOURCES += \
1415
main.cpp \
1516
inputeventhandler.cpp \
17+
proxyhandler.cpp \
1618
browser.cpp
1719

1820
RESOURCES += resources.qrc

proxyhandler.cpp

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

proxyhandler.hpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* qt-kiosk-browser
3+
* Copyright (C) 2018
4+
* O.S. Systems Sofware LTDA: [email protected]
5+
*
6+
* SPDX-License-Identifier: GPL-3.0
7+
*/
8+
9+
10+
#ifndef PROXYHANDLER_HPP
11+
#define PROXYHANDLER_HPP
12+
13+
#include <QObject>
14+
#include <QNetworkProxy>
15+
#include <QByteArray>
16+
#include <QUrl>
17+
18+
class ProxyHandler : public QObject
19+
{
20+
Q_OBJECT
21+
public:
22+
void printCurrentProxySettings();
23+
Q_INVOKABLE void useSystemProxy();
24+
};
25+
26+
#endif // PROXYHANDLER_HPP

0 commit comments

Comments
 (0)