Skip to content

Commit

Permalink
[BUGFIX][Server] Quickfix in QgsHttpTransaction to support HTTPS scheme
Browse files Browse the repository at this point in the history
The class QgsHttpTransaction is only used in server for getting files provided by URL. This class does not support HTTPS.

This is a quickfix to enable requesting SLD files provided through HTTPS scheme.

Fixes #6898 *QGIS mapserver forces http when requesting SLD=https* https://issues.qgis.org/issues/6898 a five year old issue.
  • Loading branch information
rldhont committed Sep 10, 2018
1 parent 2a1459c commit a5dd6eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/core/qgshttptransaction.sip
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class QgsHttpTransaction : QObject

void networkTimedOut();

/**
* Handle SSL errors
* @since QGIS 2.18.24
*/
void handleSslErrors( const QList<QSslError> &errors );

/** Aborts the current transaction*/
void abort();

Expand Down
21 changes: 20 additions & 1 deletion src/core/qgshttptransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "qgshttptransaction.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsconfig.h"

#include <QApplication>
Expand All @@ -30,6 +31,7 @@
#include <QTimer>

static int HTTP_PORT_DEFAULT = 80;
static int HTTPS_PORT_DEFAULT = 443;

//XXX Set the connection name when creating the provider instance
//XXX in qgswmsprovider. When creating a QgsHttpTransaction, pass
Expand Down Expand Up @@ -118,7 +120,14 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
// Set the user agent to QGIS plus the version name
header.setValue( "User-agent", QString( "QGIS - " ) + VERSION );
// Set the host in the QHttp object
http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
if ( qurl.scheme() == QString( "https" ) )
{
http->setHost( qurl.host(), QHttp::ConnectionModeHttps, qurl.port( HTTPS_PORT_DEFAULT ) );
}
else
{
http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
}
// Set the username and password if supplied for this connection
// If we have username and password set in header
if ( !mUserName.isEmpty() && !mPassword.isEmpty() )
Expand Down Expand Up @@ -189,6 +198,9 @@ bool QgsHttpTransaction::getSynchronously( QByteArray &respondedContent, int red
connect( http, SIGNAL( stateChanged( int ) ),
this, SLOT( dataStateChanged( int ) ) );

connect( http, SIGNAL( sslErrors( const QList<QSslError>& ) ),
this, SLOT( handleSslErrors( const QList<QSslError>& ) ) );

// Set up the watchdog timer
connect( mWatchdogTimer, SIGNAL( timeout() ),
this, SLOT( networkTimedOut() ) );
Expand Down Expand Up @@ -485,6 +497,13 @@ void QgsHttpTransaction::dataStateChanged( int state )
}
}

void QgsHttpTransaction::handleSslErrors( const QList<QSslError> &errors )
{
Q_FOREACH ( const QSslError &e, errors )
{
QgsMessageLog::logMessage( e.errorString() );
}
}

void QgsHttpTransaction::networkTimedOut()
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgshttptransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define QGSHTTPTRANSACTION_H

#include <QHttp>
#include <QSslError>
#include <QNetworkProxy>
#include <QString>

Expand Down Expand Up @@ -114,6 +115,12 @@ class CORE_EXPORT QgsHttpTransaction : public QObject

void networkTimedOut();

/**
* Handle SSL errors
* @since QGIS 2.18.24
*/
void handleSslErrors( const QList<QSslError> &errors );

/** Aborts the current transaction*/
void abort();

Expand Down

0 comments on commit a5dd6eb

Please sign in to comment.