Skip to content

Commit 329b9d7

Browse files
committedNov 26, 2014
Renamed plugin hook responseReady to responseComplete
added sendResponse hook and passed pluginFilters to request handler
1 parent 8bd78b3 commit 329b9d7

File tree

7 files changed

+75
-25
lines changed

7 files changed

+75
-25
lines changed
 

‎python/server/qgsserverfilter.sip

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ public:
4848
* parameters, just before entering the main switch for core services.*/
4949
virtual void requestReady();
5050
/** Method called when the QgsRequestHandler processing has done and
51-
* the response is ready, just after the main switch for core services.
51+
* the response is ready, just after the main switch for core services
52+
* and before final sending response to FCGI stdout.
5253
*/
53-
virtual void responseReady();
54+
virtual void responseComplete();
55+
/** Method called when the QgsRequestHandler sends its data to FCGI stdout.
56+
* This normally occours at the end of core services processing just after
57+
* the responseComplete() plugin hook. For streaming services (like WFS on
58+
* getFeature requests, sendResponse() might have been called several times
59+
* before the response is complete: in this particular case, sendResponse()
60+
* is called once for each feature before hitting responseComplete()
61+
*/
62+
virtual void sendResponse();
5463

5564
};

‎src/mapserver/qgis_map_serv.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,14 @@ int main( int argc, char * argv[] )
370370
{
371371
filtersIterator.value()->requestReady();
372372
}
373+
374+
//Pass the filters to the requestHandler, this is needed for the following reasons:
375+
// 1. allow core services to access plugin filters and implement thir own plugin hooks
376+
// 2. allow requestHandler to call Response
377+
378+
//TODO: implement this in the requestHandler ctor (far easier if we will get rid of
379+
// MAPSERVER_HAVE_PYTHON_PLUGINS
380+
theRequestHandler->setPluginFilters( pluginFilters );
373381
#endif
374382

375383
// Copy the parameters map
@@ -431,15 +439,12 @@ int main( int argc, char * argv[] )
431439
} // end if not exception raised
432440

433441
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
434-
// Call responseReady plugin filters in reverse order
435-
filtersIterator = pluginFilters.constEnd();
436-
while ( filtersIterator != pluginFilters.constBegin() )
442+
// Iterate filters and call their responseComplete() method
443+
for ( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator )
437444
{
438-
--filtersIterator;
439-
filtersIterator.value()->responseReady();
445+
filtersIterator.value()->responseComplete();
440446
}
441447
#endif
442-
443448
theRequestHandler->sendResponse();
444449

445450
if ( logLevel < 1 )

‎src/mapserver/qgshttprequesthandler.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &form
6363

6464
bool QgsHttpRequestHandler::responseReady() const
6565
{
66-
return mHeaders.count() || ( mBody.size() && mInfoFormat.length() );
66+
return mHeaders.count() || mBody.size();
6767
}
6868

6969
bool QgsHttpRequestHandler::exceptionRaised() const
@@ -132,28 +132,45 @@ void QgsHttpRequestHandler::sendHeaders()
132132
printf( "\n" );
133133
}
134134
printf( "\n" );
135+
mHeaders.clear();
135136
mHeadersSent = TRUE;
136137
}
137138

138139
void QgsHttpRequestHandler::sendBody() const
139140
{
140141
size_t result = fwrite( (void*)mBody.data(), mBody.size(), 1, FCGI_stdout );
141142
#ifdef QGISDEBUG
142-
QgsDebugMsg( QString( "Sent %1 blocks of %2 bytes" ).arg( result, mBody.size() ) );
143+
QgsDebugMsg( QString( "Sent %1 blocks of %2 bytes" ).arg( result ).arg( mBody.size() ) );
143144
#else
144145
Q_UNUSED( result );
145146
#endif
146147
}
147148

149+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
150+
void QgsHttpRequestHandler::setPluginFilters( QgsServerFiltersMap pluginFilters )
151+
{
152+
mPluginFilters = pluginFilters;
153+
}
154+
#endif
155+
148156
void QgsHttpRequestHandler::sendResponse()
149157
{
150158
QgsDebugMsg( QString( "Sending HTTP response" ) );
151159
if ( ! responseReady() )
152160
{
153-
QgsDebugMsg( QString( "Trying to send out an empty reponse" ) );
161+
QgsDebugMsg( QString( "Trying to send out an invalid response" ) );
154162
return;
155163
}
156-
if ( ! mHeadersSent )
164+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
165+
// Plugin hook
166+
// Iterate filters and call their sendResponse() method
167+
QgsServerFiltersMap::const_iterator filtersIterator;
168+
for ( filtersIterator = mPluginFilters.constBegin(); filtersIterator != mPluginFilters.constEnd(); ++filtersIterator )
169+
{
170+
filtersIterator.value()->sendResponse();
171+
}
172+
#endif
173+
if (! headersSent() )
157174
{
158175
sendHeaders();
159176
}

‎src/mapserver/qgshttprequesthandler.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ class QgsHttpRequestHandler: public QgsRequestHandler
5555
virtual void setInfoFormat( const QString &format );
5656
virtual bool responseReady() const;
5757
virtual bool exceptionRaised() const;
58-
virtual void setParameter( const QString &key, const QString &value );
59-
virtual QString parameter( const QString &key ) const;
60-
virtual int removeParameter( const QString &key );
61-
58+
virtual void setParameter(const QString &key, const QString &value);
59+
virtual QString parameter(const QString &key) const;
60+
virtual int removeParameter(const QString &key);
61+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
62+
virtual void setPluginFilters( QgsServerFiltersMap pluginFilters );
63+
#endif
6264
protected:
6365
virtual void sendHeaders( );
6466
virtual void sendBody( ) const;

‎src/mapserver/qgsrequesthandler.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@
2222
#ifndef QGSREQUESTHANDLER_H
2323
#define QGSREQUESTHANDLER_H
2424

25+
//Needed for MAPSERVER_HAVE_PYTHON_PLUGINS
26+
#include "qgsconfig.h"
27+
2528
#include <QMap>
2629
#include <QString>
2730
#include <QStringList>
2831

32+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
33+
#include "qgsserverfilter.h"
34+
#endif
35+
2936
class QDomDocument;
3037
class QImage;
3138
class QgsMapServiceException;
@@ -64,6 +71,8 @@ class QgsRequestHandler
6471
virtual void clearBody( ) = 0;
6572
virtual QByteArray* body( ) { return &mBody; }
6673
virtual void setInfoFormat( const QString &format ) = 0;
74+
/**Check if the response headers or the response body are not empty*/
75+
virtual bool responseReady() const = 0;
6776
/**Send out HTTP headers and flush output buffer*/
6877
virtual void sendResponse( ) = 0;
6978
/**Pointer to last raised exception*/
@@ -76,22 +85,24 @@ class QgsRequestHandler
7685
/**Return a request parameter*/
7786
virtual QString parameter( const QString &key ) const = 0;
7887
/**Return the response body*/
79-
virtual QByteArray* body( ) { return &mBody; }
8088
/**Return the requested format string*/
8189
QString format() const { return mFormat; }
8290
/**Return the mime type for the response*/
8391
QString infoFormat() const { return mInfoFormat; }
8492
/**Return true if the HTTP headers were already sent to the client*/
8593
bool headersSent() { return mHeadersSent; }
86-
QString infoFormat() const { return mInfoFormat; }
87-
88-
protected:
89-
94+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
95+
/**Allow core services to call plugin hooks through sendResponse() */
96+
virtual void setPluginFilters( QgsServerFiltersMap pluginFilters ) = 0;
97+
#endif
98+
protected:
9099
virtual void sendHeaders( ) = 0;
91100
virtual void sendBody( ) const = 0;
101+
#ifdef MAPSERVER_HAVE_PYTHON_PLUGINS
102+
QgsServerFiltersMap mPluginFilters;
103+
#endif
92104
QByteArray mBody; // The response payload
93105
/**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
94-
QByteArray mBody; // The response payload
95106
QString mFormat;
96107
QString mFormatString; //format string as it is passed in the request (with base)
97108
bool mHeadersSent;

‎src/mapserver/qgsserverfilter.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ void QgsServerFilter::requestReady()
4242
QgsDebugMsg( "QgsServerFilter plugin default requestReady called");
4343
}
4444

45-
void QgsServerFilter::responseReady()
45+
void QgsServerFilter::responseComplete()
4646
{
47-
QgsDebugMsg( "QgsServerFilter plugin default responseReady called");
47+
QgsDebugMsg( "QgsServerFilter plugin default responseComplete called");
4848
}
4949

50+
51+
void QgsServerFilter::sendResponse()
52+
{
53+
QgsDebugMsg( "QgsServerFilter plugin default sendResponse called");
54+
}

‎src/mapserver/qgsserverfilter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class QgsServerFilter
4141
virtual ~QgsServerFilter();
4242
QgsServerInterface* serverInterface( ) { return mServerInterface; }
4343
virtual void requestReady();
44-
virtual void responseReady();
44+
virtual void responseComplete();
45+
virtual void sendResponse();
4546

4647
private:
4748

0 commit comments

Comments
 (0)
Please sign in to comment.