Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 9563b04
Show file tree
Hide file tree
Showing 57 changed files with 1,116 additions and 233 deletions.
1 change: 1 addition & 0 deletions python/server/auto_additions/qgsserverrequest.py
@@ -1,2 +1,3 @@
# The following has been generated automatically from src/server/qgsserverrequest.h
QgsServerRequest.Method.baseClass = QgsServerRequest
QgsServerRequest.RequestHeader.baseClass = QgsServerRequest
2 changes: 0 additions & 2 deletions python/server/auto_generated/qgsaccesscontrol.sip.in
Expand Up @@ -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 );
Expand Down
12 changes: 12 additions & 0 deletions python/server/auto_generated/qgsfcgiserverrequest.sip.in
Expand Up @@ -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

};
Expand Down
3 changes: 1 addition & 2 deletions python/server/auto_generated/qgsservercachemanager.sip.in
Expand Up @@ -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
Expand Down
62 changes: 49 additions & 13 deletions python/server/auto_generated/qgsserverprojectutils.sip.in
Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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
};

Expand Down
53 changes: 52 additions & 1 deletion python/server/auto_generated/qgsserverrequest.sip.in
Expand Up @@ -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
Expand Down Expand Up @@ -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

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

:param name:

.. versionadded:: 3.20
%End

virtual QByteArray data() const;
Expand All @@ -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 );
Expand All @@ -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

};

Expand Down
12 changes: 12 additions & 0 deletions python/server/auto_generated/qgsserversettings.sip.in
Expand Up @@ -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,
};
};

Expand Down Expand Up @@ -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 );
Expand Down
3 changes: 1 addition & 2 deletions src/server/qgsaccesscontrol.cpp
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/server/qgsaccesscontrol.h
Expand Up @@ -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;

Expand Down

0 comments on commit 9563b04

Please sign in to comment.