Skip to content
Permalink
Browse files

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 b48c2dc41609b05c747055891569517af7390b5f
@@ -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() + "/";
@@ -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() );
@@ -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() )
@@ -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() );
@@ -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();
@@ -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() );

@@ -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();
@@ -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 )
@@ -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" ) );
@@ -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" )
{
@@ -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:" ) )
@@ -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:" ) )
@@ -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()
@@ -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;
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>475</width>
<height>400</height>
<height>415</height>
</rect>
</property>
<property name="windowTitle">
@@ -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>

0 comments on commit b48c2dc

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