Skip to content
Permalink
Browse files

Restored streaming capabilities, added mHeadersSent flag and accessor

Funded by ItOpen - http://www.itopen.it
  • Loading branch information
elpaso committed Nov 4, 2014
1 parent 840fcf3 commit a4fb2a102ee66a411067d71a6a4788ca121178d5
@@ -36,6 +36,7 @@ QgsHttpRequestHandler::QgsHttpRequestHandler():
QgsRequestHandler()
{
mException = NULL;
mHeadersSent = FALSE;
}

QgsHttpRequestHandler::~QgsHttpRequestHandler()
@@ -57,7 +58,7 @@ void QgsHttpRequestHandler::setHttpResponse( QByteArray *ba, const QString &form
}
QgsDebugMsg( "Byte array looks good, setting response..." );

mBody.append( *ba );
appendBody( *ba );
mInfoFormat = format;
}

@@ -103,7 +104,7 @@ void QgsHttpRequestHandler::setInfoFormat( const QString &format )
mInfoFormat = format;
}

void QgsHttpRequestHandler::sendHeaders() const
void QgsHttpRequestHandler::sendHeaders()
{
// Send default headers if they've not been set in a previous stage
if ( mHeaders.empty() )
@@ -113,8 +114,11 @@ void QgsHttpRequestHandler::sendHeaders() const
printf( "Content-Type: " );
printf( mInfoFormat.toLocal8Bit() );
printf( "\n" );
printf( "Content-Length: %d\n", mBody.size() );

// size is not known when streaming
if ( mBody.size() > 0)
{
printf( "Content-Length: %d\n", mBody.size() );
}
}
else
{
@@ -129,28 +133,34 @@ void QgsHttpRequestHandler::sendHeaders() const
printf( "\n" );
}
printf( "\n" );
mHeadersSent = TRUE;
}

void QgsHttpRequestHandler::sendBody() const
{
size_t result = fwrite( (void*)mBody.data(), mBody.size(), 1, FCGI_stdout );
fwrite( (void*)mBody.data(), mBody.size(), 1, FCGI_stdout );
#ifdef QGISDEBUG
QgsDebugMsg( QString( "Sent %1 bytes" ).arg( result ) );
QgsDebugMsg( QString( "Sent %1 bytes" ).arg( mBody.size() ) );
#else
Q_UNUSED( result );
#endif
}

void QgsHttpRequestHandler::sendResponse() const
void QgsHttpRequestHandler::sendResponse()
{
QgsDebugMsg( QString( "Sending HTTP response" ) );
if ( ! responseReady() )
{
QgsDebugMsg( QString( "Trying to send out an empty reponse" ) );
return;
}
sendHeaders();
if (! mHeadersSent )
{
sendHeaders();
}
sendBody();
//Clear the body to allow for streaming content to stdout
clearBody();
}


@@ -232,7 +242,6 @@ void QgsHttpRequestHandler::setGetMapResponse( const QString& service, QImage* i
{
ba = ba.toBase64();
}

setHttpResponse( &ba, formatToMimeType( mFormat ) );
}
}
@@ -426,6 +435,8 @@ bool QgsHttpRequestHandler::startGetFeatureResponse( QByteArray* ba, const QStri

setHeader( "Content-Type", format );
appendBody( *ba );
// Streaming
sendResponse();
return true;
}

@@ -441,6 +452,8 @@ void QgsHttpRequestHandler::setGetFeatureResponse( QByteArray* ba )
return;
}
appendBody( *ba );
// Streaming
sendResponse();
}

void QgsHttpRequestHandler::endGetFeatureResponse( QByteArray* ba )
@@ -449,7 +462,9 @@ void QgsHttpRequestHandler::endGetFeatureResponse( QByteArray* ba )
{
return;
}
mBody.append(ba->data());
appendBody( *ba );
// Streaming
sendResponse();
}

void QgsHttpRequestHandler::setGetCoverageResponse( QByteArray* ba )
@@ -45,7 +45,8 @@ class QgsHttpRequestHandler: public QgsRequestHandler
virtual void setGetFeatureResponse( QByteArray* ba );
virtual void endGetFeatureResponse( QByteArray* ba );
virtual void setGetCoverageResponse( QByteArray* ba );
virtual void sendResponse() const;
/**Send out HTTP headers and flush output buffer*/
virtual void sendResponse();
virtual void setHeader( const QString &name, const QString &value );
virtual int removeHeader( const QString &name );
virtual void clearHeaders( );
@@ -59,7 +60,7 @@ class QgsHttpRequestHandler: public QgsRequestHandler
virtual int removeParameter(const QString &key);

protected:
virtual void sendHeaders( ) const;
virtual void sendHeaders( );
virtual void sendBody( ) const;
void setHttpResponse(QByteArray *ba, const QString &format );
/**Converts format to official mimetype (e.g. 'jpg' to 'image/jpeg')
@@ -63,7 +63,8 @@ class QgsRequestHandler
/**Clears the response body*/
virtual void clearBody( ) = 0;
virtual void setInfoFormat( const QString &format ) = 0;
virtual void sendResponse( ) const = 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;
@@ -75,14 +76,16 @@ class QgsRequestHandler
/**Return a request parameter*/
virtual QString parameter(const QString &key) const = 0;
QString format() const { return mFormat; }
bool headersSent() { return mHeadersSent; }

protected:

virtual void sendHeaders( ) const = 0;
virtual void sendHeaders( ) = 0;
virtual void sendBody( ) const = 0;
/**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
QString mFormat;
QString mFormatString; //format string as it is passed in the request (with base)
bool mHeadersSent;
QString mService;
QString mInfoFormat;
QgsMapServiceException* mException; // Stores the exception
@@ -106,7 +106,7 @@ void QgsWFSServer::executeRequest()
mRequestHandler->setServiceException( ex );
return;
}
QgsDebugMsg( "seting GetCapabilities response" );
QgsDebugMsg( "Setting GetCapabilities response" );
mRequestHandler->setGetCapabilitiesResponse( capabilitiesDocument );
return;
}
@@ -122,7 +122,7 @@ void QgsWFSServer::executeRequest()
mRequestHandler->setServiceException( ex );
return;
}
QgsDebugMsg( "seting GetCapabilities response" );
QgsDebugMsg( "Setting GetCapabilities response" );
mRequestHandler->setGetCapabilitiesResponse( describeDocument );
return;
}
@@ -153,7 +153,7 @@ void QgsWFSServer::executeRequest()
mRequestHandler->setServiceException( ex );
return;
}
QgsDebugMsg( "seting Transaction response" );
QgsDebugMsg( "Setting Transaction response" );
mRequestHandler->setGetCapabilitiesResponse( transactionDocument );
return;
}
@@ -160,7 +160,7 @@ void QgsWMSServer::executeRequest()

if ( result )
{
QgsDebugMsg( "seting GetMap response" );
QgsDebugMsg( "Setting GetMap response" );
mRequestHandler->setGetMapResponse( "WMS", result, getImageQuality() );
QgsDebugMsg( "Response sent" );
}
@@ -258,8 +258,8 @@ void QgsWMSServer::executeRequest()

if ( result )
{
QgsDebugMsg( "seting GetLegendGraphic response" );
//seting is the same for GetMap and GetLegendGraphic
QgsDebugMsg( "Setting GetLegendGraphic response" );
//setting is the same for GetMap and GetLegendGraphic
mRequestHandler->setGetMapResponse( "WMS", result, getImageQuality() );
QgsDebugMsg( "Response sent" );
}

0 comments on commit a4fb2a1

Please sign in to comment.
You can’t perform that action at this time.