Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

http referer for wm(t)s requests #488

Merged
merged 4 commits into from

3 participants

@edigonzales

Added an option to set a http referer for wms/wmts requests. I tried to apply this for wfs and wcs too but it got too complicated at the moment. And the option is only visible and applied for wms/wmts requests.

It would be nice to have a more generic way for header parameters.

@jef-n
Owner

What needs that parameter? Couldn't it be added to the initial url?

@edigonzales

Some wm(t)s providers need a referer for credentials stuff.

@mhugent
Owner

@jef: afaik the referer needs to be added as a header and cannot be passed as part of the url

@jef-n jef-n merged commit b48c2dc into qgis:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2013
  1. @edigonzales
Commits on Mar 29, 2013
  1. referer works for wms/wmts

    Stefan Ziegler authored
  2. referer for wfs: one has to modify a lot... stop here and consider on…

    Stefan Ziegler authored
    …ly wms
  3. back to wms only

    Stefan Ziegler authored
This page is out of date. Refresh to see the latest.
View
4 src/gui/qgsmanageconnectionsdialog.cpp
@@ -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() )
View
9 src/gui/qgsnewhttpconnection.cpp
@@ -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() );
View
6 src/providers/wms/qgswmsconnection.cpp
@@ -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();
View
15 src/providers/wms/qgswmsprovider.cpp
@@ -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()
View
3  src/providers/wms/qgswmsprovider.h
@@ -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;
View
12 src/ui/qgsnewhttpconnectionbase.ui
@@ -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>
Something went wrong with that request. Please try again.