Skip to content
Permalink
Browse files

Merge pull request #41333 from sbrunner/configurable-serviceurl

[Server][Feature][needs-docs] Make service URL configurable
  • Loading branch information
elpaso committed Apr 15, 2021
2 parents fbb7eaa + 3202e3a commit 9563b040ef37aee51db54a8074227ca4e2886767
Showing with 1,116 additions and 233 deletions.
  1. +1 −0 python/server/auto_additions/qgsserverrequest.py
  2. +0 −2 python/server/auto_generated/qgsaccesscontrol.sip.in
  3. +12 −0 python/server/auto_generated/qgsfcgiserverrequest.sip.in
  4. +1 −2 python/server/auto_generated/qgsservercachemanager.sip.in
  5. +49 −13 python/server/auto_generated/qgsserverprojectutils.sip.in
  6. +52 −1 python/server/auto_generated/qgsserverrequest.sip.in
  7. +12 −0 python/server/auto_generated/qgsserversettings.sip.in
  8. +1 −2 src/server/qgsaccesscontrol.cpp
  9. +0 −1 src/server/qgsaccesscontrol.h
  10. +79 −31 src/server/qgsfcgiserverrequest.cpp
  11. +11 −0 src/server/qgsfcgiserverrequest.h
  12. +15 −9 src/server/qgsservercachemanager.cpp
  13. +5 −3 src/server/qgsservercachemanager.h
  14. +1 −1 src/server/qgsserverinterfaceimpl.cpp
  15. +135 −8 src/server/qgsserverprojectutils.cpp
  16. +53 −13 src/server/qgsserverprojectutils.h
  17. +32 −3 src/server/qgsserverrequest.cpp
  18. +58 −4 src/server/qgsserverrequest.h
  19. +82 −0 src/server/qgsserversettings.cpp
  20. +11 −0 src/server/qgsserversettings.h
  21. +4 −4 src/server/services/landingpage/qgslandingpagehandlers.cpp
  22. +2 −1 src/server/services/landingpage/qgslandingpagehandlers.h
  23. +5 −5 src/server/services/landingpage/qgslandingpageutils.cpp
  24. +3 −2 src/server/services/landingpage/qgslandingpageutils.h
  25. +1 −1 src/server/services/wcs/qgswcsgetcapabilities.cpp
  26. +2 −6 src/server/services/wcs/qgswcsutils.cpp
  27. +2 −1 src/server/services/wcs/qgswcsutils.h
  28. +4 −4 src/server/services/wfs/qgswfsgetcapabilities.cpp
  29. +1 −1 src/server/services/wfs/qgswfsgetcapabilities.h
  30. +3 −3 src/server/services/wfs/qgswfsgetcapabilities_1_0_0.cpp
  31. +1 −1 src/server/services/wfs/qgswfsgetcapabilities_1_0_0.h
  32. +9 −9 src/server/services/wfs/qgswfsgetfeature.cpp
  33. +2 −5 src/server/services/wfs/qgswfsutils.cpp
  34. +2 −1 src/server/services/wfs/qgswfsutils.h
  35. +3 −3 src/server/services/wms/qgswmsdescribelayer.cpp
  36. +20 −18 src/server/services/wms/qgswmsgetcapabilities.cpp
  37. +1 −1 src/server/services/wms/qgswmsgetcapabilities.h
  38. +1 −1 src/server/services/wms/qgswmsgetcontext.cpp
  39. +3 −5 src/server/services/wms/qgswmsutils.cpp
  40. +2 −1 src/server/services/wms/qgswmsutils.h
  41. +3 −3 src/server/services/wmts/qgswmtsgetcapabilities.cpp
  42. +1 −1 src/server/services/wmts/qgswmtsgetcapabilities.h
  43. +2 −6 src/server/services/wmts/qgswmtsutils.cpp
  44. +2 −1 src/server/services/wmts/qgswmtsutils.h
  45. +52 −2 tests/src/python/test_qgsserver.py
  46. +1 −0 tests/src/python/test_qgsserver_landingpage.py
  47. +4 −4 tests/src/python/test_qgsserver_wms.py
  48. +320 −0 tests/testdata/qgis_server/getcapabilities-map.txt
  49. +8 −8 tests/testdata/qgis_server/getcapabilities.txt
  50. +1 −1 tests/testdata/qgis_server/getcapabilities_without_map_param.txt
  51. +17 −17 tests/testdata/qgis_server/landingpage/test_landing_page_with_pg_index.json
  52. +5 −5 tests/testdata/qgis_server/landingpage/test_project_Project1_Title.json
  53. +5 −5 tests/testdata/qgis_server/landingpage/test_project_Project2_Title.json
  54. +5 −5 tests/testdata/qgis_server/landingpage/test_project_Project3_Title.json
  55. +5 −5 tests/testdata/qgis_server/landingpage/test_project_QGIS_Server_-_Grouped_Nested_Layer.json
  56. +1 −1 tests/testdata/qgis_server/wms_getcapabilities_empty_layer.txt
  57. +3 −3 tests/testdata/qgis_server_accesscontrol/results/getcapabilities_wms_dimension.txt
@@ -1,2 +1,3 @@
# The following has been generated automatically from src/server/qgsserverrequest.h
QgsServerRequest.Method.baseClass = QgsServerRequest
QgsServerRequest.RequestHeader.baseClass = QgsServerRequest
@@ -134,8 +134,6 @@ Are we authorized to modify the following geometry
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 = QgsServerSettings() );
%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,30 @@ class QgsServerRequest
PatchMethod
};

enum RequestHeader
{
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
HOST,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
// https://tools.ietf.org/html/rfc7239
FORWARDED,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
X_FORWARDED_FOR,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
X_FORWARDED_HOST,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
X_FORWARDED_PROTO,
// The QGIS service URL
X_QGIS_SERVICE_URL,
// The QGIS WMS service URL
X_QGIS_WMS_SERVICE_URL,
// The QGIS WFS service URL
X_QGIS_WFS_SERVICE_URL,
// The QGIS WCS service URL
X_QGIS_WCS_SERVICE_URL,
// The QGIS WMTS service URL
X_QGIS_WMTS_SERVICE_URL,
};

QgsServerRequest();
%Docstring
@@ -115,12 +139,21 @@ 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

:param name: of the header

:return: the header value or an empty string
%End

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

:param headerEnum: of the header

:return: the header value or an empty string
%End

@@ -144,6 +177,8 @@ Returns the header map
Remove an header

:param name:

.. versionadded:: 3.20
%End

virtual QByteArray data() const;
@@ -166,6 +201,16 @@ 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 );
@@ -191,6 +236,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 );
@@ -190,12 +190,11 @@ bool QgsAccessControl::fillCacheKey( QStringList &cacheKey ) const
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;
}
return true;
}
@@ -147,7 +147,6 @@ 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;

0 comments on commit 9563b04

Please sign in to comment.