Http request/response handler refactoring.

HTTP Request handler now manages HTTP request and response.

* added methods to manage HTTP response headers
* added methods to manage response body
* added accessors API methods for request parameters and
  response headers and body
This commit is contained in:
elpaso 2014-10-09 11:23:55 +02:00
parent f00db954a3
commit 2bb7f19638
2 changed files with 36 additions and 1 deletions

View File

@ -37,6 +37,11 @@
#include "qgsnetworkaccessmanager.h"
#include "qgsmaplayerregistry.h"
#include "qgsserverlogger.h"
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
#include "qgsserverplugins.h"
#include "qgsserverfilter.h"
#include "qgsserverinterfaceimpl.h"
#endif
#include <QDomDocument>
#include <QNetworkDiskCache>
@ -315,6 +320,18 @@ int main( int argc, char * argv[] )
int logLevel = QgsServerLogger::instance()->logLevel();
QTime time; //used for measuring request time if loglevel < 1
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
// Create the interface
QgsServerInterfaceImpl serverIface( &capabilitiesCache );
// Init plugins
if (! QgsServerPlugins::initPlugins( &serverIface ) )
{
QgsMessageLog::logMessage( "No server plugins are available", "Server", QgsMessageLog::INFO );
}
// Store plugin filters for faster access
QMultiMap<int, QgsServerFilter*> pluginFilters = serverIface.filters();
#endif
while ( fcgi_accept() >= 0 )
{
QgsMapLayerRegistry::instance()->removeAllMapLayers();
@ -340,6 +357,17 @@ int main( int argc, char * argv[] )
theRequestHandler->setServiceException( e );
}
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
// Set the request handler into the interface for plugins to manipulate it
serverIface.setRequestHandler( theRequestHandler.data() );
// Iterate filters and call their requestReady() method
QgsServerFiltersMap::const_iterator filtersIterator;
for( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator)
{
filtersIterator.value()->requestReady();
}
#endif
// Copy the parameters map
QMap<QString, QString> parameterMap( theRequestHandler->parameterMap() );
@ -398,6 +426,14 @@ int main( int argc, char * argv[] )
} // end switch
} // end if not exception raised
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
// Call responseReady plugin filters
for(filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator)
{
filtersIterator.value()->responseReady();
}
#endif
theRequestHandler->sendResponse();
if ( logLevel < 1 )

View File

@ -65,7 +65,6 @@ class QgsRequestHandler
virtual void setInfoFormat( const QString &format ) = 0;
/**Send out HTTP headers and flush output buffer*/
virtual void sendResponse( ) = 0;
virtual bool responseReady() const = 0;
/**Pointer to last raised exception*/
virtual bool exceptionRaised() const = 0;
QMap<QString, QString> parameterMap( ) { return mParameterMap; }