KDSoap icon indicating copy to clipboard operation
KDSoap copied to clipboard

Respect web proxy environment settings

Open Massimo-B opened this issue 6 years ago • 4 comments

Just like https://sourceforge.net/p/gsoap2/bugs/1115/, KDSoap could respect the http_proxy https_proxy and no_proxy environment settings in order to make the user configure the proxy later. Currently this can only be done outside of KDSoap by setting the QNetworkProxy. This was mentioned in #99.

However for the kdwsdl compiler this issue becomes more inconvenient, when it tries to download included xsd code:

kdwsdl2cpp -o Extensions.h Extensions.wsdl 
Warning: Definitions: unknown tag wsp:UsingPolicy
Warning: Definitions: unknown tag wsp:Policy
Warning: Definitions: unknown tag wsp:Policy
importing schema at http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader
Downloading 'http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader'
Error downloading 'http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader': Socket operation timed out
Warning: PortType: unknown tag wsp:Policy
Warning: Operation: unknown tag wsp:Policy
No service tag found in the wsdl file, generating one service per binding 
Converting 0 simple types 
Converting 0 complex types 

However this could be worked around using some wrapper like tsocks.

Massimo-B avatar Jul 11 '17 11:07 Massimo-B

IMHO that's Qt's job.

But actually, it looks like qtbase/src/network/kernel/qnetworkproxy_generic.cpp already queries these env vars. This just needs to be enabled.

Can you test if adding QNetworkProxyFactory::setUseSystemConfiguration(true); in kdwsdl2cpp's main fixes it? I guess I could merge that in.

dfaure-kdab avatar Jul 17 '17 09:07 dfaure-kdab

I changed main like this:

diff --git a/kdwsdl2cpp/src/main.cpp b/kdwsdl2cpp/src/main.cpp
index 306a269..6524296 100644
--- a/kdwsdl2cpp/src/main.cpp
+++ b/kdwsdl2cpp/src/main.cpp
@@ -26,6 +26,7 @@
 #include <QTimer>
 #include <QCoreApplication>
 #include <QDebug>
+#include <QNetworkProxyFactory>
 
 static const char *WSDL2CPP_DESCRIPTION = "KDAB's WSDL to C++ compiler";
 static const char *WSDL2CPP_VERSION_STR = "2.0";
@@ -146,6 +147,8 @@ int main(int argc, char **argv)
     Settings::self()->setNameSpace(nameSpace);
     Settings::self()->setOptionalElementType(optionalElementType);
     KWSDL::Compiler compiler;
+    
+    QNetworkProxyFactory::setUseSystemConfiguration(true);
 
     // so that we have an event loop, for downloads
     QTimer::singleShot(0, &compiler, SLOT(run()));

I rerun both kdwsdl2cpp for .h and .cpp, recompiled, but it did not work eventhough the environment is set:

$ env |grep prox
https_proxy=http://proxy:8080
http_proxy=http://proxy:8080
no_proxy=10.0.0.0/8,127.0.0.1,172.16.0.0/12,192.168.20.0/24

Isn't setUseSystemConfiguration(true) the default anyway?

Massimo-B avatar Jul 28 '17 12:07 Massimo-B

Hi, I still need to set the proxy manually and the environment settings are ignored:

    m_service.clientInterface()->setProxy(proxy);

Massimo-B avatar Nov 14 '17 14:11 Massimo-B

Hi, in applications using QNetworkAccessManager it's possible to do

m_networkAccessManager.proxyFactory()->setUseSystemConfiguration(true);

In KDSOAP I only found

QNetworkProxy KDSoapClientInterface::proxy 	() 

Is there any way to get access to the QNetworkProxyFactory ?

Massimo-B avatar Dec 12 '17 15:12 Massimo-B