23 #include <fcgi_stdio.h>
33 mBuffer.open( QIODevice::ReadWrite );
39 mHeaders.remove( key );
44 mHeaders.insert( key, value );
49 return mHeaders.value( key );
60 mHeaders.insert( QStringLiteral(
"Status" ), QStringLiteral(
" %1" ).arg( code ) );
75 setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/html;charset=utf-8" ) );
76 write( QStringLiteral(
"<html><body>%1</body></html>" ).arg( message ) );
95 if ( ! mHeaders.contains(
"Content-Length" ) )
97 mHeaders.insert( QStringLiteral(
"Content-Length" ), QString::number( mBuffer.pos() ) );
106 if ( ! mHeadersSent )
109 QMap<QString, QString>::const_iterator it;
110 for ( it = mHeaders.constBegin(); it != mHeaders.constEnd(); ++it )
112 fputs( it.key().toUtf8(), FCGI_stdout );
113 fputs(
": ", FCGI_stdout );
114 fputs( it.value().toUtf8(), FCGI_stdout );
115 fputs(
"\n", FCGI_stdout );
117 fputs(
"\n", FCGI_stdout );
126 mBuffer.buffer().clear();
128 else if ( mBuffer.bytesAvailable() > 0 )
130 QByteArray &ba = mBuffer.buffer();
131 size_t count = fwrite( (
void * )ba.data(), ba.size(), 1, FCGI_stdout );
133 qDebug() << QStringLiteral(
"Sent %1 blocks of %2 bytes" ).arg( count ).arg( ba.size() );
147 mBuffer.buffer().clear();
156 return mBuffer.data();
163 mBuffer.buffer().clear();
169 setHeader( QStringLiteral(
"Server" ), QStringLiteral(
" QGIS FCGI server - QGIS version %1" ).arg(
Qgis::version() ) );
static QString version()
Version string.
void setDefaultHeaders()
Set the default headers.
void clear() override
Reset all headers and content for this response.
void setHeader(const QString &key, const QString &value) override
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
void flush() override
Flushes the current output buffer to the network.
void removeHeader(const QString &key) override
Clear header Undo a previous 'setHeader' call.
QByteArray data() const override
Gets the data written so far.
QIODevice * io() override
Returns the underlying QIODevice.
bool headersSent() const override
Returns true if the headers have already been sent.
void setStatusCode(int code) override
Set the http status code.
QgsFcgiServerResponse(QgsServerRequest::Method method=QgsServerRequest::GetMethod)
Constructor for QgsFcgiServerResponse.
void sendError(int code, const QString &message) override
Send error This method delegates error handling at the server level.
void truncate() override
Truncate data.
void finish() override
Finish the response, ending the transaction.
QString header(const QString &key) const override
Returns the header value.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Method
HTTP Method (or equivalent) used for the request.
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.