25 #include "qgsconfig.h"
27 #include <QApplication>
43 QNetworkProxy::ProxyType proxyType,
46 : httpresponsecontenttype(
"" )
48 , httphost( proxyHost )
51 Q_UNUSED( proxyPort );
52 Q_UNUSED( proxyUser );
53 Q_UNUSED( proxyPass );
54 Q_UNUSED( proxyType );
99 QHttpRequestHeader header(
"GET", qurl.host() );
103 header.setValue(
"Host", qurl.host() );
107 header.setValue(
"Host", QString(
"%1:%2" ).arg( qurl.host() ).arg( qurl.port() ) );
110 header.setValue(
"User-agent", QString(
"QGIS - " ) + VERSION );
129 httphost = settings.value(
"proxy/proxyHost",
"" ).toString();
130 httpport = settings.value(
"proxy/proxyPort",
"" ).toString().toInt();
137 QgsDebugMsg(
"qurl.host() is '" + qurl.host() +
"'." );
147 QString pathAndQuery =
httpurl.remove( 0,
httpurl.indexOf( qurl.host() ) );
148 pathAndQuery =
httpurl.remove( 0, pathAndQuery.indexOf( qurl.path() ) );
151 header.setRequest(
"GET", pathAndQuery );
157 header.setRequest(
"POST", pathAndQuery );
162 connect(
http, SIGNAL( requestStarted(
int ) ),
165 connect(
http, SIGNAL( responseHeaderReceived(
const QHttpResponseHeader& ) ),
168 connect(
http, SIGNAL( readyRead(
const QHttpResponseHeader& ) ),
169 this, SLOT(
dataReceived(
const QHttpResponseHeader& ) ) );
174 connect(
http, SIGNAL( requestFinished(
int,
bool ) ),
177 connect(
http, SIGNAL( done(
bool ) ),
180 connect(
http, SIGNAL( stateChanged(
int ) ),
199 qApp->processEvents();
255 QgsDebugMsg(
"ID=" + QString::number(
id ) +
"." );
262 QString::number( resp.statusCode() ) +
", reason '" + resp.reasonPhrase() +
"', content type: '" +
263 resp.value(
"Content-Type" ) +
"'." );
268 if ( resp.statusCode() == 302 )
274 else if ( resp.statusCode() == 200 )
280 mError =
tr(
"WMS Server responded unexpectedly with HTTP Status Code %1 (%2)" )
281 .arg( resp.statusCode() )
282 .arg( resp.reasonPhrase() );
299 if ( 0 <
http->readBlock( temp,
http->bytesAvailable() ) )
323 status =
tr(
"Received %1 of %2 bytes" ).arg( done ).arg( total );
327 status =
tr(
"Received %1 bytes (total unknown)" ).arg( done );
337 QgsDebugMsg(
"ID=" + QString::number(
id ) +
"." );
350 QgsDebugMsg(
"http activity loop already false." );
359 mError =
tr(
"HTTP response completed, however there was an error: %1" ).arg(
http->errorString() );
410 mError =
tr(
"HTTP transaction completed, however there was an error: %1" ).arg(
http->errorString() );
430 QgsDebugMsg(
"state " + QString::number( state ) +
"." );
437 case QHttp::Unconnected:
438 QgsDebugMsg(
"There is no connection to the host." );
442 case QHttp::HostLookup:
443 QgsDebugMsg(
"A host name lookup is in progress." );
448 case QHttp::Connecting:
449 QgsDebugMsg(
"An attempt to connect to the host is in progress." );
455 QgsDebugMsg(
"The client is sending its request to the server." );
461 QgsDebugMsg(
"The client's request has been sent and the client is reading the server's response." );
466 case QHttp::Connected:
467 QgsDebugMsg(
"The connection to the host is open, but the client is neither sending a request, nor waiting for a response." );
473 QgsDebugMsg(
"The connection is closing down, but is not yet closed. (The state will be Unconnected when the connection is closed.)" );
485 mError =
tr(
"Network timed out after %n second(s) of inactivity.\n"
486 "This may be a problem in your network connection or at the WMS server.",
"inactivity timeout",
mNetworkTimeoutMsec / 1000 );
503 bool proxyEnabled = settings.value(
"proxy/proxyEnabled",
false ).toBool();
510 QString proxyExcludedURLs = settings.value(
"proxy/proxyExcludedUrls",
"" ).toString();
511 if ( !proxyExcludedURLs.isEmpty() )
513 QStringList excludedURLs = proxyExcludedURLs.split(
"|" );
514 QStringList::const_iterator exclIt = excludedURLs.constBegin();
515 for ( ; exclIt != excludedURLs.constEnd(); ++exclIt )
517 if ( url.startsWith( *exclIt ) )
525 QString proxyHost = settings.value(
"proxy/proxyHost",
"" ).toString();
526 int proxyPort = settings.value(
"proxy/proxyPort",
"" ).toString().toInt();
527 QString proxyUser = settings.value(
"proxy/proxyUser",
"" ).toString();
528 QString proxyPassword = settings.value(
"proxy/proxyPassword",
"" ).toString();
530 QString proxyTypeString = settings.value(
"proxy/proxyType",
"" ).toString();
531 QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
532 if ( proxyTypeString ==
"DefaultProxy" )
534 proxyType = QNetworkProxy::DefaultProxy;
536 else if ( proxyTypeString ==
"Socks5Proxy" )
538 proxyType = QNetworkProxy::Socks5Proxy;
540 else if ( proxyTypeString ==
"HttpProxy" )
542 proxyType = QNetworkProxy::HttpProxy;
544 else if ( proxyTypeString ==
"HttpCachingProxy" )
546 proxyType = QNetworkProxy::HttpCachingProxy;
548 else if ( proxyTypeString ==
"FtpCachingProxy" )
550 proxyType = QNetworkProxy::FtpCachingProxy;
552 http.setProxy( QNetworkProxy( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );
bool httpactive
Indicates if the transaction is in progress.
QgsHttpTransaction()
Default constructor is forbidden.
int httpid
Indicates the QHttp ID.
QString errorString()
If an operation returns 0 (e.g.
void dataReadProgress(int theProgress)
Signal for progress update.
QString mPassword
Password.
QString httphost
The host being used for this transaction.
int mNetworkTimeoutMsec
Network timeout in milliseconds.
QHttp * http
Indicates the associated QHttp object.
void setCredentials(const QString &username, const QString &password)
Set the credentials (username and password)
void dataProgress(int done, int total)
QString httpresponsecontenttype
void totalSteps(int theTotalSteps)
Signal for adjusted number of steps.
QString responseContentType()
void dataFinished(int id, bool error)
QString mUserName
User name.
QString httpurl
The original URL requested for this transaction.
virtual ~QgsHttpTransaction()
Destructor.
QString mError
The error message associated with the last HTTP error.
void dataStateChanged(int state)
HTTP request/response manager that is redirect-aware.
void statusChanged(QString theStatusQString)
emit a signal to be caught by qgisapp and display a msg on status bar
bool getSynchronously(QByteArray &respondedContent, int redirections=0, const QByteArray *postData=0)
Gets the response synchronously.
int httpredirections
Number of http redirections this transaction has been subjected to.
void abort()
Aborts the current transaction.
QString httpredirecturl
If not empty, indicates that the QHttp is a redirect to the contents of this variable.
void dataReceived(const QHttpResponseHeader &resp)
void transactionFinished(bool error)
void dataHeaderReceived(const QHttpResponseHeader &resp)
QTimer * mWatchdogTimer
Indicates the associated QTimer object - used to detect network timeouts.
static int HTTP_PORT_DEFAULT
static bool applyProxySettings(QHttp &http, const QString &url)
Apply proxy settings from QSettings to a http object.