|
27 | 27 |
|
28 | 28 | #include <QApplication> |
29 | 29 | #include <QUrl> |
| 30 | +#include <QSettings> |
30 | 31 | #include <QTimer> |
31 | 32 | #include "qgslogger.h" |
32 | 33 |
|
@@ -97,17 +98,17 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red |
97 | 98 | // Set the host in the QHttp object |
98 | 99 | http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) ); |
99 | 100 |
|
100 | | - if ( httphost.isEmpty() ) |
| 101 | + if(!QgsHttpTransaction::applyProxySettings(*http, httpurl)) |
101 | 102 | { |
102 | | - // No proxy was specified - connect directly to host in URI |
103 | 103 | httphost = qurl.host(); |
104 | 104 | httpport = qurl.port( HTTP_PORT_DEFAULT ); |
105 | | - |
106 | 105 | } |
107 | 106 | else |
108 | 107 | { |
109 | | - // Insert proxy username and password authentication |
110 | | - http->setProxy( QNetworkProxy(mProxyType, httphost, httpport, httpuser, httppass) ); |
| 108 | + //proxy enabled, read httphost and httpport from settings |
| 109 | + QSettings settings; |
| 110 | + httphost = settings.value( "proxy/proxyHost", "" ).toString(); |
| 111 | + httpport = settings.value( "proxy/proxyPort", "" ).toString().toInt(); |
111 | 112 | } |
112 | 113 |
|
113 | 114 | // int httpid1 = http->setHost( qurl.host(), qurl.port() ); |
@@ -470,6 +471,63 @@ QString QgsHttpTransaction::errorString() |
470 | 471 | return mError; |
471 | 472 | } |
472 | 473 |
|
| 474 | +bool QgsHttpTransaction::applyProxySettings(QHttp& http, const QString& url) |
| 475 | +{ |
| 476 | + QSettings settings; |
| 477 | + //check if proxy is enabled |
| 478 | + bool proxyEnabled = settings.value( "proxy/proxyEnabled", false ).toBool(); |
| 479 | + if(!proxyEnabled) |
| 480 | + { |
| 481 | + return false; |
| 482 | + } |
| 483 | + |
| 484 | + //check if the url should go through proxy |
| 485 | + QString proxyExcludedURLs = settings.value( "proxy/proxyExcludedUrls", "").toString(); |
| 486 | + if(!proxyExcludedURLs.isEmpty()) |
| 487 | + { |
| 488 | + QStringList excludedURLs = proxyExcludedURLs.split("|"); |
| 489 | + QStringList::const_iterator exclIt = excludedURLs.constBegin(); |
| 490 | + for(; exclIt != excludedURLs.constEnd(); ++exclIt) |
| 491 | + { |
| 492 | + if(url.startsWith(*exclIt)) |
| 493 | + { |
| 494 | + return false; //url does not go through proxy |
| 495 | + } |
| 496 | + } |
| 497 | + } |
| 498 | + |
| 499 | + //read type, host, port, user, passw from settings |
| 500 | + QString proxyHost = settings.value( "proxy/proxyHost", "" ).toString(); |
| 501 | + int proxyPort = settings.value( "proxy/proxyPort", "" ).toString().toInt(); |
| 502 | + QString proxyUser = settings.value( "proxy/proxyUser", "" ).toString(); |
| 503 | + QString proxyPassword = settings.value( "proxy/proxyPassword", "" ).toString(); |
| 504 | + |
| 505 | + QString proxyTypeString = settings.value( "proxy/proxyType", "" ).toString(); |
| 506 | + QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy; |
| 507 | + if(proxyTypeString == "DefaultProxy") |
| 508 | + { |
| 509 | + proxyType = QNetworkProxy::DefaultProxy; |
| 510 | + } |
| 511 | + else if(proxyTypeString == "Socks5Proxy") |
| 512 | + { |
| 513 | + proxyType = QNetworkProxy::Socks5Proxy; |
| 514 | + } |
| 515 | + else if(proxyTypeString == "HttpProxy") |
| 516 | + { |
| 517 | + proxyType = QNetworkProxy::HttpProxy; |
| 518 | + } |
| 519 | + else if(proxyTypeString == "HttpCachingProxy") |
| 520 | + { |
| 521 | + proxyType = QNetworkProxy::HttpCachingProxy; |
| 522 | + } |
| 523 | + else if(proxyTypeString == "FtpCachingProxy") |
| 524 | + { |
| 525 | + proxyType = QNetworkProxy::FtpCachingProxy; |
| 526 | + } |
| 527 | + http.setProxy( QNetworkProxy(proxyType, proxyHost, proxyPort, proxyUser, proxyPassword) ); |
| 528 | + return true; |
| 529 | +} |
| 530 | + |
473 | 531 | void QgsHttpTransaction::abort() |
474 | 532 | { |
475 | 533 | if(http) |
|
0 commit comments