Skip to content

Commit ade381f

Browse files
author
Stefan Ziegler
committed
referer for wfs: one has to modify a lot... stop here and consider only wms
1 parent b06eeca commit ade381f

6 files changed

+33
-5
lines changed

src/core/qgsowsconnection.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString &
9393
mUri.setParam( "password", password );
9494
}
9595

96+
QString referer = settings.value( key + "/referer" ).toString();
97+
if ( !referer.isEmpty() )
98+
{
99+
mUri.setParam( "referer", referer );
100+
}
101+
96102
bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
97103
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
98104
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();

src/gui/qgsmanageconnectionsdialog.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &
347347
el.setAttribute( "invertAxisOrientation", settings.value( path + connections[i] + "/invertAxisOrientation", false ).toBool() ? "true" : "false" );
348348
}
349349

350+
el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() );
351+
350352
path = "/Qgis/" + service.toUpper() + "/";
351353
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
352354
el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
@@ -372,6 +374,8 @@ QDomDocument QgsManageConnectionsDialog::saveWFSConnections( const QStringList &
372374
el.setAttribute( "name", connections[ i ] );
373375
el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() );
374376

377+
el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() );
378+
375379
path = "/Qgis/WFS/";
376380
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
377381
el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
@@ -576,6 +580,7 @@ void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, co
576580
settings.setValue( QString( "/" + connectionName + "/ignoreGetFeatureInfoURI" ), child.attribute( "ignoreGetFeatureInfoURI" ) == "true" );
577581
settings.setValue( QString( "/" + connectionName + "/ignoreAxisOrientation" ), child.attribute( "ignoreAxisOrientation" ) == "true" );
578582
settings.setValue( QString( "/" + connectionName + "/invertAxisOrientation" ), child.attribute( "invertAxisOrientation" ) == "true" );
583+
settings.setValue( QString( "/" + connectionName + "/referer" ), child.attribute( "referer" ) );
579584
settings.endGroup();
580585

581586
if ( !child.attribute( "username" ).isEmpty() )
@@ -656,6 +661,7 @@ void QgsManageConnectionsDialog::loadWFSConnections( const QDomDocument &doc, co
656661
// no dups detected or overwrite is allowed
657662
settings.beginGroup( "/Qgis/connections-wfs" );
658663
settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) );
664+
settings.setValue( QString( "/" + connectionName + "/referer" ), child.attribute( "referer" ) );
659665
settings.endGroup();
660666

661667
if ( !child.attribute( "username" ).isEmpty() )

src/gui/qgsnewhttpconnection.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ QgsNewHttpConnection::QgsNewHttpConnection(
5555
cbxIgnoreAxisOrientation->setChecked( settings.value( key + "/ignoreAxisOrientation", false ).toBool() );
5656
cbxInvertAxisOrientation->setChecked( settings.value( key + "/invertAxisOrientation", false ).toBool() );
5757
cbxIgnoreGetFeatureInfoURI->setChecked( settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool() );
58+
59+
txtReferer->setText( settings.value( key + "/referer" ).toString() );
5860

5961
txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
6062
txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
61-
txtReferer->setText( settings.value( credentialsKey + "/referer" ).toString() );
6263
}
6364

6465
if ( mBaseKey != "/Qgis/connections-wms/" )
@@ -159,9 +160,10 @@ void QgsNewHttpConnection::accept()
159160
settings.setValue( key + "/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
160161
}
161162

163+
settings.setValue( key + "/referer", txtReferer->text() );
164+
162165
settings.setValue( credentialsKey + "/username", txtUserName->text() );
163166
settings.setValue( credentialsKey + "/password", txtPassword->text() );
164-
settings.setValue( credentialsKey + "/referer", txtReferer->text() );
165167

166168
settings.setValue( mBaseKey + "/selected", txtName->text() );
167169

src/providers/wfs/qgswfscapabilities.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ QgsWFSCapabilities::QgsWFSCapabilities( QString theUri ) :
3636
mBaseUrl = prepareUri( mUri.param( "url" ) );
3737

3838
QgsDebugMsg( "mBaseUrl = " + mBaseUrl );
39-
39+
4040
//find out the server URL
4141
/*
4242
QSettings settings;
@@ -142,10 +142,20 @@ void QgsWFSCapabilities::requestCapabilities()
142142

143143
QNetworkRequest request( uriGetCapabilities() );
144144
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
145+
setReferer( request );
145146
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
146147
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
147148
}
148149

150+
void QgsWFSCapabilities::setReferer( QNetworkRequest &request ) const
151+
{
152+
QString referer = mUri.param( "referer" );
153+
if ( !referer.isNull() )
154+
{
155+
request.setRawHeader( "Referer", QString( "%1" ).arg( referer ).toAscii() );
156+
}
157+
}
158+
149159
void QgsWFSCapabilities::capabilitiesReplyFinished()
150160
{
151161
// handle network errors

src/providers/wfs/qgswfscapabilities.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgsdatasourceuri.h"
2222

2323
class QNetworkReply;
24+
class QNetworkRequest;
2425

2526
class QgsWFSCapabilities : public QObject
2627
{
@@ -47,7 +48,10 @@ class QgsWFSCapabilities : public QObject
4748

4849
//! start network connection to get capabilities
4950
void requestCapabilities();
50-
51+
52+
//! set referer header
53+
void setReferer( QNetworkRequest &request ) const;
54+
5155
//! description of a vector layer
5256
struct FeatureType
5357
{

src/providers/wms/qgswmsconnection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
6767
mUri.setParam( "password", password );
6868
}
6969

70-
QString referer = settings.value( credentialsKey + "/referer" ).toString();
70+
QString referer = settings.value( key + "/referer" ).toString();
7171
if ( !referer.isEmpty() )
7272
{
7373
mUri.setParam( "referer", referer );

0 commit comments

Comments
 (0)