qgis / QGIS-Enhancement-Proposals

QEP's (QGIS Enhancement Proposals) are used in the process of creating and discussing new enhancements for QGIS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Qgis server filter method for inspecting project before processing request.

dmarteau opened this issue · comments

QGIS Enhancement: Add Qgis server filter method for inspecting project before processing request.

Date 2021/09/30

Author David Marteau (@dmarteau)

Contact dmarteau at 3liz dot com

maintainer @dmarteau

Version QGIS 3.24

Summary

In server filter, there is actually no way to inspect the loaded project before the request is processed.

This may be a problem when one wants to inspect the loaded project
and modify the request parameter accordingly or inspect the project before processing the request.

The actual workflow is:

No project loaded from here

  • onRequestReady() <- parameters may be modified here, eventually modifying project source parameter

Project is loaded

<<< Missing method here

Project is available from QgsProject::instance

  • onSendResponse() <- Request is beeing processed
  • onResponseComplete() <- Request has been processed

Rationale

QgsServer may be used in several ways:

  • Directly with the provided fcgi module
  • Embedded in larger project

In the latter case a QgsProject may be directly passed to QgsServer::handleRequest;
in this case the config cache is not sollicited and the project instance is passed
as is to the services/api processing.

This enable embedders to:

  • Use their own implementation of cache for bypassing limitations of the actual implemention (as projects stored in redis cache or alternative cache)
  • Dynamically create a custom ad-hoc project and use it as source for server requests.

In these situations, the config cache is useless; worst, in the second
case, there is no url to rely on for loading project for inspection - which in all case, would be ineficient because the project would
be loaded twice.

As filters implementors should not rely on details of implementation of how the project is created. The proposed solution must
be independant of any caching solution.

Proposed Solution

To solve this, the proposed solution is to add a new method bool QgsServerFilter::onProjectReady( QgsProject* project ) (refer to qgis/QGIS#45158 for the explanation of the syntax of this method)

This method would be called just before passing the request to the service or api when the project is made available (either from beeing passed directly or from the internal config cache.

Example(s)

Insertion point In qgsserver.cpp - QgsServer::handleRequest

        ...

        QgsProject::setInstance( const_cast<QgsProject *>( project ) );

        if ( project )
        {
          sServerInterface->setConfigFilePath( project->fileName() );
          // Call filter's `onProjectReady( project )`
          responseDecorator.projectReady( project );
        }

        ...

Affected Files

  • qgsserver.cpp : call response decorator
  • qgsserverfilter.[h|cpp]: implement QgsServerFilter::onProjectReady( QgsProject* project )
  • qgsfilterresponsedecorator.[h|cpp]: QgsFilterResponseDecorator::projectReady( QgsProject* project ) delegate call to filter's method.

Performance Implications

None directly: depends on filter implementation.

Votes

(required)