Skip to content
Permalink
Browse files

[BUGFIX][Server] Quickfix in QgsHttpTransaction to support HTTPS scheme

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 a5dd6eb877fd1208fc10897625eb3d94768ea297
Showing with 33 additions and 1 deletion.
  1. +6 −0 python/core/qgshttptransaction.sip
  2. +20 −1 src/core/qgshttptransaction.cpp
  3. +7 −0 src/core/qgshttptransaction.h
@@ -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();

@@ -22,6 +22,7 @@

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

#include <QApplication>
@@ -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
@@ -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() )
@@ -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() ) );
@@ -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()
{
@@ -22,6 +22,7 @@
#define QGSHTTPTRANSACTION_H

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

@@ -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();

0 comments on commit a5dd6eb

Please sign in to comment.
You can’t perform that action at this time.