Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #488 from edigonzales/master
http referer for wm(t)s requests
  • Loading branch information
jef-n committed Apr 2, 2013
2 parents 255b467 + 1b7d94b commit b48c2dc
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/gui/qgsmanageconnectionsdialog.cpp
Expand Up @@ -345,6 +345,7 @@ QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &
el.setAttribute( "ignoreGetFeatureInfoURI", settings.value( path + connections[i] + "/ignoreGetFeatureInfoURI", false ).toBool() ? "true" : "false" );
el.setAttribute( "ignoreAxisOrientation", settings.value( path + connections[i] + "/ignoreAxisOrientation", false ).toBool() ? "true" : "false" );
el.setAttribute( "invertAxisOrientation", settings.value( path + connections[i] + "/invertAxisOrientation", false ).toBool() ? "true" : "false" );
el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() );
}

path = "/Qgis/" + service.toUpper() + "/";
Expand Down Expand Up @@ -372,6 +373,8 @@ QDomDocument QgsManageConnectionsDialog::saveWFSConnections( const QStringList &
el.setAttribute( "name", connections[ i ] );
el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() );

el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() );

path = "/Qgis/WFS/";
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
Expand Down Expand Up @@ -576,6 +579,7 @@ void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, co
settings.setValue( QString( "/" + connectionName + "/ignoreGetFeatureInfoURI" ), child.attribute( "ignoreGetFeatureInfoURI" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/ignoreAxisOrientation" ), child.attribute( "ignoreAxisOrientation" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/invertAxisOrientation" ), child.attribute( "invertAxisOrientation" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/referer" ), child.attribute( "referer" ) );
settings.endGroup();

if ( !child.attribute( "username" ).isEmpty() )
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsnewhttpconnection.cpp
Expand Up @@ -55,6 +55,8 @@ QgsNewHttpConnection::QgsNewHttpConnection(
cbxIgnoreAxisOrientation->setChecked( settings.value( key + "/ignoreAxisOrientation", false ).toBool() );
cbxInvertAxisOrientation->setChecked( settings.value( key + "/invertAxisOrientation", false ).toBool() );
cbxIgnoreGetFeatureInfoURI->setChecked( settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool() );

txtReferer->setText( settings.value( key + "/referer" ).toString() );

txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
Expand All @@ -79,6 +81,11 @@ QgsNewHttpConnection::QgsNewHttpConnection(

cbxIgnoreGetFeatureInfoURI->setVisible( false );
mGroupBox->layout()->removeWidget( cbxIgnoreGetFeatureInfoURI );

txtReferer->setVisible( false );
mGroupBox->layout()->removeWidget( txtReferer );
lblReferer->setVisible( false );
mGroupBox->layout()->removeWidget( lblReferer );

// Adjust height
int w = width();
Expand Down Expand Up @@ -158,6 +165,8 @@ void QgsNewHttpConnection::accept()
settings.setValue( key + "/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
}

settings.setValue( key + "/referer", txtReferer->text() );

settings.setValue( credentialsKey + "/username", txtUserName->text() );
settings.setValue( credentialsKey + "/password", txtPassword->text() );

Expand Down
6 changes: 6 additions & 0 deletions src/providers/wms/qgswmsconnection.cpp
Expand Up @@ -67,6 +67,12 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
mUri.setParam( "password", password );
}

QString referer = settings.value( key + "/referer" ).toString();
if ( !referer.isEmpty() )
{
mUri.setParam( "referer", referer );
}

bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
Expand Down
15 changes: 12 additions & 3 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -97,6 +97,7 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri )
, mErrors( 0 )
, mUserName( QString::null )
, mPassword( QString::null )
, mReferer( QString::null )
, mTiled( false )
, mTileLayer( 0 )
, mTileMatrixSetId( QString::null )
Expand Down Expand Up @@ -161,6 +162,9 @@ bool QgsWmsProvider::parseUri( QString uriString )

mPassword = uri.param( "password" );
QgsDebugMsg( "set password to " + mPassword );

mReferer = uri.param( "referer" );
QgsDebugMsg( "set referer to " + mReferer );

addLayers( uri.params( "layers" ), uri.params( "styles" ) );
setImageEncoding( uri.param( "format" ) );
Expand Down Expand Up @@ -1597,7 +1601,7 @@ bool QgsWmsProvider::parseCapabilitiesDom( QByteArray const &xml, QgsWmsCapabili
QDomElement e = n.toElement(); // try to convert the node to an element.
if ( !e.isNull() )
{
//QgsDebugMsg(e.tagName() ); // the node really is an element.
QgsDebugMsg(e.tagName() ); // the node really is an element.

if ( e.tagName() == "Service" || e.tagName() == "ows:ServiceProvider" || e.tagName() == "ows:ServiceIdentification" )
{
Expand Down Expand Up @@ -2232,7 +2236,7 @@ void QgsWmsProvider::parseLayer( QDomElement const & e, QgsWmsLayerProperty& lay
QDomElement e1 = n1.toElement(); // try to convert the node to an element.
if ( !e1.isNull() )
{
//QgsDebugMsg( " " + e1.tagName() ); // the node really is an element.
QgsDebugMsg( " " + e1.tagName() ); // the node really is an element.

QString tagName = e1.tagName();
if ( tagName.startsWith( "wms:" ) )
Expand Down Expand Up @@ -3006,7 +3010,7 @@ bool QgsWmsProvider::parseServiceExceptionReportDom( QByteArray const & xml )
QDomElement e = n.toElement(); // try to convert the node to an element.
if ( !e.isNull() )
{
//QgsDebugMsg(e.tagName() ); // the node really is an element.
QgsDebugMsg(e.tagName() ); // the node really is an element.

QString tagName = e.tagName();
if ( tagName.startsWith( "wms:" ) )
Expand Down Expand Up @@ -4360,6 +4364,11 @@ void QgsWmsProvider::setAuthorization( QNetworkRequest &request ) const
{
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName ).arg( mPassword ).toAscii().toBase64() );
}

if ( !mReferer.isNull() )
{
request.setRawHeader( "Referer", QString( "%1" ).arg( mReferer ).toAscii() );
}
}

QVector<QgsWmsSupportedFormat> QgsWmsProvider::supportedFormats()
Expand Down
3 changes: 3 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -1064,6 +1064,9 @@ class QgsWmsProvider : public QgsRasterDataProvider

//! Password for basic http authentication
QString mPassword;

//! Referer for http requests
QString mReferer;

//! layer is tiled, tile layer and active matrix set
bool mTiled;
Expand Down
12 changes: 11 additions & 1 deletion src/ui/qgsnewhttpconnectionbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>475</width>
<height>400</height>
<height>415</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -162,6 +162,16 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="txtReferer"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lblReferer">
<property name="text">
<string>Referer</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit b48c2dc

Please sign in to comment.