Skip to content
Permalink
Browse files

[Server][Feature][needs-docs] Make service URL configurable

The goals are:
* To have better result in the GetCapabilities URL without having to fill it in the Project configuration
* Be able to be set by an integrator with environment variable or by providing headers from a proxy

The server resolution will use the following order:
 - Value defined in the project per service.
 - The ``<service>_SERVICE_URL`` environment variable.
 - The ``SERVICE_URL`` environment variable.
 - The custom ``X-Qgis-<service>-Servcie-Url`` header.
 - The custom ``X-Qgis-Service-Url`` header.
 - Build form the standard ``Forwarded`` header.
 - Build form the pseudo standard ``X-Forwarded-Host`` and ``X-Forwarded-Proto`` headers.
 - Build form the standard ``Host`` header and the server protocol.
 - Build form the server name and the server protocol.
  • Loading branch information
sbrunner committed Mar 12, 2021
1 parent 3f5b165 commit af01a41e3ae7331b67c46b9da2e2bfa2d4c1633b
Showing with 1,072 additions and 235 deletions.
  1. +1 −3 python/server/auto_generated/qgsaccesscontrol.sip.in
  2. +12 −0 python/server/auto_generated/qgsfcgiserverrequest.sip.in
  3. +1 −2 python/server/auto_generated/qgsservercachemanager.sip.in
  4. +49 −13 python/server/auto_generated/qgsserverprojectutils.sip.in
  5. +29 −1 python/server/auto_generated/qgsserverrequest.sip.in
  6. +12 −0 python/server/auto_generated/qgsserversettings.sip.in
  7. +3 −5 src/server/qgsaccesscontrol.cpp
  8. +1 −2 src/server/qgsaccesscontrol.h
  9. +79 −31 src/server/qgsfcgiserverrequest.cpp
  10. +11 −0 src/server/qgsfcgiserverrequest.h
  11. +15 −9 src/server/qgsservercachemanager.cpp
  12. +5 −3 src/server/qgsservercachemanager.h
  13. +1 −1 src/server/qgsserverinterfaceimpl.cpp
  14. +135 −8 src/server/qgsserverprojectutils.cpp
  15. +53 −13 src/server/qgsserverprojectutils.h
  16. +23 −3 src/server/qgsserverrequest.cpp
  17. +43 −1 src/server/qgsserverrequest.h
  18. +82 −0 src/server/qgsserversettings.cpp
  19. +11 −0 src/server/qgsserversettings.h
  20. +4 −4 src/server/services/landingpage/qgslandingpagehandlers.cpp
  21. +2 −1 src/server/services/landingpage/qgslandingpagehandlers.h
  22. +5 −5 src/server/services/landingpage/qgslandingpageutils.cpp
  23. +3 −2 src/server/services/landingpage/qgslandingpageutils.h
  24. +1 −1 src/server/services/wcs/qgswcsgetcapabilities.cpp
  25. +2 −6 src/server/services/wcs/qgswcsutils.cpp
  26. +2 −1 src/server/services/wcs/qgswcsutils.h
  27. +4 −4 src/server/services/wfs/qgswfsgetcapabilities.cpp
  28. +1 −1 src/server/services/wfs/qgswfsgetcapabilities.h
  29. +3 −3 src/server/services/wfs/qgswfsgetcapabilities_1_0_0.cpp
  30. +1 −1 src/server/services/wfs/qgswfsgetcapabilities_1_0_0.h
  31. +9 −9 src/server/services/wfs/qgswfsgetfeature.cpp
  32. +2 −5 src/server/services/wfs/qgswfsutils.cpp
  33. +2 −1 src/server/services/wfs/qgswfsutils.h
  34. +3 −3 src/server/services/wms/qgswmsdescribelayer.cpp
  35. +20 −18 src/server/services/wms/qgswmsgetcapabilities.cpp
  36. +1 −1 src/server/services/wms/qgswmsgetcapabilities.h
  37. +1 −1 src/server/services/wms/qgswmsgetcontext.cpp
  38. +3 −5 src/server/services/wms/qgswmsutils.cpp
  39. +2 −1 src/server/services/wms/qgswmsutils.h
  40. +3 −3 src/server/services/wmts/qgswmtsgetcapabilities.cpp
  41. +1 −1 src/server/services/wmts/qgswmtsgetcapabilities.h
  42. +2 −6 src/server/services/wmts/qgswmtsutils.cpp
  43. +2 −1 src/server/services/wmts/qgswmtsutils.h
  44. +52 −2 tests/src/python/test_qgsserver.py
  45. +1 −0 tests/src/python/test_qgsserver_landingpage.py
  46. +4 −4 tests/src/python/test_qgsserver_wms.py
  47. +320 −0 tests/testdata/qgis_server/getcapabilities-map.txt
  48. +8 −8 tests/testdata/qgis_server/getcapabilities.txt
  49. +1 −1 tests/testdata/qgis_server/getcapabilities_without_map_param.txt
  50. +17 −17 tests/testdata/qgis_server/landingpage/test_landing_page_with_pg_index.json
  51. +5 −5 tests/testdata/qgis_server/landingpage/test_project_Project1_Title.json
  52. +5 −5 tests/testdata/qgis_server/landingpage/test_project_Project2_Title.json
  53. +5 −5 tests/testdata/qgis_server/landingpage/test_project_Project3_Title.json
  54. +5 −5 tests/testdata/qgis_server/landingpage/test_project_QGIS_Server_-_Grouped_Nested_Layer.json
  55. +1 −1 tests/testdata/qgis_server/wms_getcapabilities_empty_layer.txt
  56. +3 −3 tests/testdata/qgis_server_accesscontrol/results/getcapabilities_wms_dimension.txt
@@ -129,13 +129,11 @@ Are we authorized to modify the following geometry
:return: ``True`` if we are allowed to edit the feature
%End

bool fillCacheKey( QStringList &cacheKey ) const;
void fillCacheKey( QStringList &cacheKey ) const;
%Docstring
Fill the capabilities caching key

:param cacheKey: the list to fill with a cache variant

:return: ``False`` if we can't create a cache
%End

void registerAccessControl( QgsAccessControlFilter *accessControl, int priority = 0 );
@@ -30,6 +30,18 @@ Class defining fcgi request
bool hasError() const;
%Docstring
Returns ``True`` if an error occurred during initialization
%End

virtual QString header( const QString &name ) const;

%Docstring
Returns the header value

:param name: of the header

:return: the header value or an empty string

.. versionadded:: 3.20
%End

};
@@ -22,10 +22,9 @@ A helper class that centralizes caches accesses given by all the server cache fi

%TypeHeaderCode
#include "qgsservercachemanager.h"
#include "qgsservercachefilter.h"
%End
public:
QgsServerCacheManager();
QgsServerCacheManager( const QgsServerSettings &settings );
%Docstring
Constructor
%End
@@ -355,13 +355,16 @@ Returns the restricted composer list.
:return: the restricted composer list if defined in project.
%End

QString wmsServiceUrl( const QgsProject &project );
QString wmsServiceUrl( const QgsProject &project, const QgsServerRequest &request = QgsServerRequest(), const QgsServerSettings &settings = QgsServerSettings() );
%Docstring
Returns the WMS service url defined in a QGIS project.
Returns the WMS service url.
The URL defined in the project or if not defined the URL from serviceUrl.

:param project: the QGIS project
:param request: the request
:param settings: the server settings

:return: url if defined in project, an empty string otherwise.
:return: url to use for this service
%End

QString wmsRootName( const QgsProject &project );
@@ -370,7 +373,7 @@ Returns the WMS root layer name defined in a QGIS project.

:param project: the QGIS project

:return: root layer name if defined in project, an empty string otherwise.
:return: root layer name to use for this service
%End

QStringList wmsRestrictedLayers( const QgsProject &project );
@@ -400,13 +403,16 @@ Returns the WMS Extent restriction.
:return: the WMS Extent restriction.
%End

QString wfsServiceUrl( const QgsProject &project );
QString wfsServiceUrl( const QgsProject &project, const QgsServerRequest &request = QgsServerRequest(), const QgsServerSettings &settings = QgsServerSettings() );
%Docstring
Returns the WFS service url defined in a QGIS project.
Returns the WFS service url.
The URL defined in the project or if not defined the URL from serviceUrl.

:param project: the QGIS project
:param request: the request
:param settings: the server settings

:return: url if defined in project, an empty string otherwise.
:return: url to use for this service
%End

QStringList wfsLayerIds( const QgsProject &project );
@@ -456,13 +462,16 @@ Returns the Layer ids list defined in a QGIS project as published as WFS-T with
:return: the Layer ids list.
%End

QString wcsServiceUrl( const QgsProject &project );
QString wcsServiceUrl( const QgsProject &project, const QgsServerRequest &request = QgsServerRequest(), const QgsServerSettings &settings = QgsServerSettings() );
%Docstring
Returns the WCS service url defined in a QGIS project.
Returns the WCS service url.
The URL defined in the project or if not defined the URL from serviceUrl.

:param project: the QGIS project
:param request: the request
:param settings: the server settings

:return: url if defined in project, an empty string otherwise.
:return: url to use for this service
%End

QStringList wcsLayerIds( const QgsProject &project );
@@ -474,15 +483,42 @@ Returns the Layer ids list defined in a QGIS project as published in WCS.
:return: the Layer ids list.
%End

QString wmtsServiceUrl( const QgsProject &project );
QString wmtsServiceUrl( const QgsProject &project, const QgsServerRequest &request = QgsServerRequest(), const QgsServerSettings &settings = QgsServerSettings() );
%Docstring
Returns the WMTS service url defined in a QGIS project.
Returns the WMTS service url.
The URL defined in the project or if not defined the URL from serviceUrl.

:param project: the QGIS project
:param request: the request
:param settings: the server settings

:return: url if defined in project, an empty string otherwise.
:return: url to use for this service

.. versionadded:: 3.4
%End

QString serviceUrl( const QString &service, const QgsServerRequest &request, const QgsServerSettings &settings );
%Docstring
Returns the service url defined in the environment variable or with HTTP header.
The is calculated from, in the order:

- Value defined in the project per service.
- The ``<service>_SERVICE_URL`` environment variable.
- The ``SERVICE_URL`` environment variable.
- The custom ``X-Qgis-<service>-Servcie-Url`` header.
- The custom ``X-Qgis-Service-Url`` header.
- Build form the standard ``Forwarded`` header.
- Build form the pseudo standard ``X-Forwarded-Host`` and ``X-Forwarded-Proto`` headers.
- Build form the standard ``Host`` header and the server protocol.
- Build form the server name and the server protocol.

:param request: the request
:param service: the used service
:param settings: the server settings

:return: url to use for this service

.. versionadded:: 3.20
%End
};

@@ -34,6 +34,15 @@ class QgsServerRequest
PatchMethod
};

static const QString HOST;
static const QString FORWARDED;
static const QString X_FORWARDED_HOST;
static const QString X_FORWARDED_PROTO;
static const QString X_QGIS_SERVICE_URL;
static const QString X_QGIS_WMS_SERVICE_URL;
static const QString X_QGIS_WFS_SERVICE_URL;
static const QString X_QGIS_WCS_SERVICE_URL;
static const QString X_QGIS_WMTS_SERVICE_URL;

QgsServerRequest();
%Docstring
@@ -115,7 +124,7 @@ Gets a parameter value
Remove a parameter
%End

QString header( const QString &name ) const;
virtual QString header( const QString &name ) const;
%Docstring
Returns the header value

@@ -166,11 +175,24 @@ by default this is equal to the url seen by QGIS server
.. seealso:: :py:func:`url`

.. versionadded:: 3.6
%End

QUrl baseUrl() const;
%Docstring
Returns the base URL of QGIS server

E.-g. if we call QGIS server with 'http://example.com/folder?REQUEST=WMS&...'
the base URL will be 'http://example.com/folder'

.. versionadded:: 3.20
%End

void setMethod( QgsServerRequest::Method method );
%Docstring
Set the request method

E.-g. if we call QGIS server with 'http://example.com/folder?REQUEST=WMS&...'
the base URL will be 'http://example.com/folder'
%End

const QString queryParameter( const QString &name, const QString &defaultValue = QString( ) ) const;
@@ -191,6 +213,12 @@ Set the request original ``url`` (the request url as seen by the web server)
.. versionadded:: 3.6
%End

void setBaseUrl( const QUrl &url );
%Docstring
Set the base URL of QGIS server

.. versionadded:: 3.20
%End

};

@@ -53,6 +53,11 @@ Provides some enum describing the environment currently supported for configurat
QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES,
QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS,
QGIS_SERVER_LOG_PROFILE,
QGIS_SERVER_SERVICE_URL,
QGIS_SERVER_WMS_SERVICE_URL,
QGIS_SERVER_WFS_SERVICE_URL,
QGIS_SERVER_WCS_SERVICE_URL,
QGIS_SERVER_WMTS_SERVICE_URL,
};
};

@@ -273,6 +278,13 @@ The default value is ``False``, this value can be changed by setting the environ
variable QGIS_SERVER_DISABLE_GETPRINT.

.. versionadded:: 3.16
%End

QString serviceUrl( const QString &service ) const;
%Docstring
Returns the service URL from the setting.

.. versionadded:: 3.20
%End

static QString name( QgsServerSettingsEnv::EnvVar env );
@@ -184,18 +184,16 @@ bool QgsAccessControl::allowToEdit( const QgsVectorLayer *layer, const QgsFeatur
}

//! Fill the capabilities caching key
bool QgsAccessControl::fillCacheKey( QStringList &cacheKey ) const
void QgsAccessControl::fillCacheKey( QStringList &cacheKey ) const
{
QgsAccessControlFilterMap::const_iterator acIterator;
for ( acIterator = mPluginsAccessControls->constBegin(); acIterator != mPluginsAccessControls->constEnd(); ++acIterator )
{
QString newKey = acIterator.value()->cacheKey();
if ( newKey.length() == 0 )
if ( ! newKey.isEmpty() )
{
cacheKey.clear();
return false;
cacheKey << newKey;
}
cacheKey << newKey;
}
return true;
}
@@ -147,9 +147,8 @@ class SERVER_EXPORT QgsAccessControl : public QgsFeatureFilterProvider
/**
* Fill the capabilities caching key
* \param cacheKey the list to fill with a cache variant
* \returns FALSE if we can't create a cache
*/
bool fillCacheKey( QStringList &cacheKey ) const;
void fillCacheKey( QStringList &cacheKey ) const;

/**
* Register an access control filter

0 comments on commit af01a41

Please sign in to comment.