Skip to content

Commit 8b606ce

Browse files
authored
Merge pull request #7827 from rldhont/fix-qgshttptransaction-support-https-server
[BUGFIX][Server] Quickfix in QgsHttpTransaction to support HTTPS scheme
2 parents 2a1459c + a5dd6eb commit 8b606ce

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

python/core/qgshttptransaction.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ class QgsHttpTransaction : QObject
7979

8080
void networkTimedOut();
8181

82+
/**
83+
* Handle SSL errors
84+
* @since QGIS 2.18.24
85+
*/
86+
void handleSslErrors( const QList<QSslError> &errors );
87+
8288
/** Aborts the current transaction*/
8389
void abort();
8490

src/core/qgshttptransaction.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "qgshttptransaction.h"
2424
#include "qgslogger.h"
25+
#include "qgsmessagelog.h"
2526
#include "qgsconfig.h"
2627

2728
#include <QApplication>
@@ -30,6 +31,7 @@
3031
#include <QTimer>
3132

3233
static int HTTP_PORT_DEFAULT = 80;
34+
static int HTTPS_PORT_DEFAULT = 443;
3335

3436
//XXX Set the connection name when creating the provider instance
3537
//XXX in qgswmsprovider. When creating a QgsHttpTransaction, pass
@@ -118,7 +120,14 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
118120
// Set the user agent to QGIS plus the version name
119121
header.setValue( "User-agent", QString( "QGIS - " ) + VERSION );
120122
// Set the host in the QHttp object
121-
http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
123+
if ( qurl.scheme() == QString( "https" ) )
124+
{
125+
http->setHost( qurl.host(), QHttp::ConnectionModeHttps, qurl.port( HTTPS_PORT_DEFAULT ) );
126+
}
127+
else
128+
{
129+
http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
130+
}
122131
// Set the username and password if supplied for this connection
123132
// If we have username and password set in header
124133
if ( !mUserName.isEmpty() && !mPassword.isEmpty() )
@@ -189,6 +198,9 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
189198
connect( http, SIGNAL( stateChanged( int ) ),
190199
this, SLOT( dataStateChanged( int ) ) );
191200

201+
connect( http, SIGNAL( sslErrors( const QList<QSslError>& ) ),
202+
this, SLOT( handleSslErrors( const QList<QSslError>& ) ) );
203+
192204
// Set up the watchdog timer
193205
connect( mWatchdogTimer, SIGNAL( timeout() ),
194206
this, SLOT( networkTimedOut() ) );
@@ -485,6 +497,13 @@ void QgsHttpTransaction::dataStateChanged( int state )
485497
}
486498
}
487499

500+
void QgsHttpTransaction::handleSslErrors( const QList<QSslError> &errors )
501+
{
502+
Q_FOREACH ( const QSslError &e, errors )
503+
{
504+
QgsMessageLog::logMessage( e.errorString() );
505+
}
506+
}
488507

489508
void QgsHttpTransaction::networkTimedOut()
490509
{

src/core/qgshttptransaction.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define QGSHTTPTRANSACTION_H
2323

2424
#include <QHttp>
25+
#include <QSslError>
2526
#include <QNetworkProxy>
2627
#include <QString>
2728

@@ -114,6 +115,12 @@ class CORE_EXPORT QgsHttpTransaction : public QObject
114115

115116
void networkTimedOut();
116117

118+
/**
119+
* Handle SSL errors
120+
* @since QGIS 2.18.24
121+
*/
122+
void handleSslErrors( const QList<QSslError> &errors );
123+
117124
/** Aborts the current transaction*/
118125
void abort();
119126

0 commit comments

Comments
 (0)