26 #include "qgsconfig.h"
28 #include <QApplication>
44 QNetworkProxy::ProxyType proxyType,
47 : httpresponsecontenttype(
"" )
49 , httphost( proxyHost )
94 QHttpRequestHeader header(
"GET", qurl.host() );
98 header.setValue(
"Host", qurl.host() );
102 header.setValue(
"Host", QString(
"%1:%2" ).arg( qurl.host() ).arg( qurl.port() ) );
105 header.setValue(
"User-agent", QString(
"Quantum GIS - " ) + VERSION );
124 httphost = settings.value(
"proxy/proxyHost",
"" ).toString();
125 httpport = settings.value(
"proxy/proxyPort",
"" ).toString().toInt();
132 QgsDebugMsg(
"qurl.host() is '" + qurl.host() +
"'." );
142 QString pathAndQuery =
httpurl.remove( 0,
httpurl.indexOf( qurl.host() ) );
143 pathAndQuery =
httpurl.remove( 0, pathAndQuery.indexOf( qurl.path() ) );
146 header.setRequest(
"GET", pathAndQuery );
152 header.setRequest(
"POST", pathAndQuery );
157 connect(
http, SIGNAL( requestStarted(
int ) ),
160 connect(
http, SIGNAL( responseHeaderReceived(
const QHttpResponseHeader& ) ),
163 connect(
http, SIGNAL( readyRead(
const QHttpResponseHeader& ) ),
164 this, SLOT(
dataReceived(
const QHttpResponseHeader& ) ) );
169 connect(
http, SIGNAL( requestFinished(
int,
bool ) ),
172 connect(
http, SIGNAL( done(
bool ) ),
175 connect(
http, SIGNAL( stateChanged(
int ) ),
194 qApp->processEvents();
249 QgsDebugMsg(
"ID=" + QString::number(
id ) +
"." );
256 QString::number( resp.statusCode() ) +
", reason '" + resp.reasonPhrase() +
"', content type: '" +
257 resp.value(
"Content-Type" ) +
"'." );
262 if ( resp.statusCode() == 302 )
268 else if ( resp.statusCode() == 200 )
274 mError = tr(
"WMS Server responded unexpectedly with HTTP Status Code %1 (%2)" )
275 .arg( resp.statusCode() )
276 .arg( resp.reasonPhrase() );
292 if ( 0 <
http->readBlock( temp,
http->bytesAvailable() ) )
316 status = tr(
"Received %1 of %2 bytes" ).arg( done ).arg( total );
320 status = tr(
"Received %1 bytes (total unknown)" ).arg( done );
331 QgsDebugMsg(
"ID=" + QString::number(
id ) +
"." );
344 QgsDebugMsg(
"http activity loop already false." );
353 mError = tr(
"HTTP response completed, however there was an error: %1" ).arg(
http->errorString() );
402 mError = tr(
"HTTP transaction completed, however there was an error: %1" ).arg(
http->errorString() );
420 QgsDebugMsg(
"state " + QString::number( state ) +
"." );
427 case QHttp::Unconnected:
428 QgsDebugMsg(
"There is no connection to the host." );
432 case QHttp::HostLookup:
433 QgsDebugMsg(
"A host name lookup is in progress." );
438 case QHttp::Connecting:
439 QgsDebugMsg(
"An attempt to connect to the host is in progress." );
445 QgsDebugMsg(
"The client is sending its request to the server." );
451 QgsDebugMsg(
"The client's request has been sent and the client is reading the server's response." );
456 case QHttp::Connected:
457 QgsDebugMsg(
"The connection to the host is open, but the client is neither sending a request, nor waiting for a response." );
463 QgsDebugMsg(
"The connection is closing down, but is not yet closed. (The state will be Unconnected when the connection is closed.)" );
475 mError = tr(
"Network timed out after %n second(s) of inactivity.\n"
476 "This may be a problem in your network connection or at the WMS server.",
"inactivity timeout",
mNetworkTimeoutMsec / 1000 );
493 bool proxyEnabled = settings.value(
"proxy/proxyEnabled",
false ).toBool();
500 QString proxyExcludedURLs = settings.value(
"proxy/proxyExcludedUrls",
"" ).toString();
501 if ( !proxyExcludedURLs.isEmpty() )
503 QStringList excludedURLs = proxyExcludedURLs.split(
"|" );
504 QStringList::const_iterator exclIt = excludedURLs.constBegin();
505 for ( ; exclIt != excludedURLs.constEnd(); ++exclIt )
507 if ( url.startsWith( *exclIt ) )
515 QString proxyHost = settings.value(
"proxy/proxyHost",
"" ).toString();
516 int proxyPort = settings.value(
"proxy/proxyPort",
"" ).toString().toInt();
517 QString proxyUser = settings.value(
"proxy/proxyUser",
"" ).toString();
518 QString proxyPassword = settings.value(
"proxy/proxyPassword",
"" ).toString();
520 QString proxyTypeString = settings.value(
"proxy/proxyType",
"" ).toString();
521 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
522 if ( proxyTypeString ==
"DefaultProxy" )
524 proxyType = QNetworkProxy::DefaultProxy;
526 else if ( proxyTypeString ==
"Socks5Proxy" )
528 proxyType = QNetworkProxy::Socks5Proxy;
530 else if ( proxyTypeString ==
"HttpProxy" )
532 proxyType = QNetworkProxy::HttpProxy;
534 else if ( proxyTypeString ==
"HttpCachingProxy" )
536 proxyType = QNetworkProxy::HttpCachingProxy;
538 else if ( proxyTypeString ==
"FtpCachingProxy" )
540 proxyType = QNetworkProxy::FtpCachingProxy;
542 http.setProxy( QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );