-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement QgsFcgiRequest and QgsFcgiResponse
- Loading branch information
Showing
33 changed files
with
1,101 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/*************************************************************************** | ||
qgsfcgiserverresponse.cpp | ||
Define response wrapper for fcgi response | ||
------------------- | ||
begin : 2017-01-03 | ||
copyright : (C) 2017 by David Marteau | ||
email : david dot marteau at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsbufferserverresponse.h" | ||
#include "qgslogger.h" | ||
#include "qgsmessagelog.h" | ||
|
||
#include <QDebug> | ||
|
||
// | ||
// QgsBufferServerResponse | ||
// | ||
|
||
QgsBufferServerResponse::QgsBufferServerResponse() | ||
{ | ||
mBuffer.open( QIODevice::ReadWrite ); | ||
mHeadersWritten = false; | ||
mFinished = false; | ||
mReturnCode = 200; | ||
} | ||
|
||
QgsBufferServerResponse::~QgsBufferServerResponse() | ||
{ | ||
|
||
} | ||
|
||
void QgsBufferServerResponse::clearHeader( const QString& key ) | ||
{ | ||
if ( !mHeadersWritten ) | ||
mHeaders.remove( key ); | ||
} | ||
|
||
void QgsBufferServerResponse::setHeader( const QString& key, const QString& value ) | ||
{ | ||
if ( ! mHeadersWritten ) | ||
mHeaders.insert( key, value ); | ||
} | ||
|
||
void QgsBufferServerResponse::setReturnCode( int code ) | ||
{ | ||
mReturnCode = code; | ||
} | ||
|
||
void QgsBufferServerResponse::sendError( int code, const QString& message ) | ||
{ | ||
if ( mHeadersWritten ) | ||
{ | ||
QgsMessageLog::logMessage( "Cannot send error after headers written" ); | ||
return; | ||
} | ||
|
||
clear(); | ||
setReturnCode( code ); | ||
setHeader( QStringLiteral( "Content-Type" ), QStringLiteral( "text/plain; charset=utf-8" ) ); | ||
write( message ); | ||
finish(); | ||
} | ||
|
||
QIODevice* QgsBufferServerResponse::io() | ||
{ | ||
return &mBuffer; | ||
} | ||
|
||
void QgsBufferServerResponse::finish() | ||
{ | ||
if ( mFinished ) | ||
{ | ||
QgsMessageLog::logMessage( "finish() called twice" ); | ||
return; | ||
} | ||
|
||
if ( !mHeadersWritten ) | ||
{ | ||
if ( ! mHeaders.contains( "Content-Length" ) ) | ||
{ | ||
mHeaders.insert( QStringLiteral( "Content-Length" ), QStringLiteral( "%1" ).arg( mBuffer.pos() ) ); | ||
} | ||
} | ||
flush(); | ||
mFinished = true; | ||
} | ||
|
||
void QgsBufferServerResponse::flush() | ||
{ | ||
if ( ! mHeadersWritten ) | ||
{ | ||
mHeadersWritten = true; | ||
} | ||
|
||
mBuffer.seek( 0 ); | ||
QByteArray& ba = mBuffer.buffer(); | ||
mBody.append( ba ); | ||
ba.clear(); | ||
} | ||
|
||
|
||
void QgsBufferServerResponse::clear() | ||
{ | ||
if ( !mHeadersWritten ) | ||
mHeaders.clear(); | ||
|
||
mBuffer.seek( 0 ); | ||
mBuffer.buffer().clear(); | ||
} | ||
|
||
|
||
//QgsBufferServerRequest | ||
// | ||
QgsBufferServerRequest::QgsBufferServerRequest( const QString& url, Method method, QByteArray* data ) | ||
: QgsServerRequest( url, method ) | ||
{ | ||
if ( data ) | ||
{ | ||
mData = *data; | ||
} | ||
} | ||
|
||
QgsBufferServerRequest::QgsBufferServerRequest( const QUrl& url, Method method, QByteArray* data ) | ||
: QgsServerRequest( url, method ) | ||
{ | ||
if ( data ) | ||
{ | ||
mData = *data; | ||
} | ||
} | ||
|
||
QgsBufferServerRequest::~QgsBufferServerRequest() | ||
{ | ||
} | ||
|
||
|
||
|
Oops, something went wrong.