25 #include <fcgi_stdio.h> 36 mBuffer.open( QIODevice::ReadWrite );
42 mHeaders.remove( key );
47 mHeaders.insert( key, value );
52 return mHeaders.value( key );
63 mHeaders.insert( QStringLiteral(
"Status" ), QStringLiteral(
" %1" ).arg( code ) );
78 setHeader( QStringLiteral(
"Content-Type" ), QStringLiteral(
"text/html;charset=utf-8" ) );
79 write( QStringLiteral(
"<html><body>%1</body></html>" ).arg( message ) );
98 if ( ! mHeaders.contains(
"Content-Length" ) )
100 mHeaders.insert( QStringLiteral(
"Content-Length" ), QStringLiteral(
"%1" ).arg( mBuffer.pos() ) );
109 if ( ! mHeadersSent )
112 QMap<QString, QString>::const_iterator it;
113 for ( it = mHeaders.constBegin(); it != mHeaders.constEnd(); ++it )
115 fputs( it.key().toUtf8(), FCGI_stdout );
116 fputs(
": ", FCGI_stdout );
117 fputs( it.value().toUtf8(), FCGI_stdout );
118 fputs(
"\n", FCGI_stdout );
120 fputs(
"\n", FCGI_stdout );
129 mBuffer.buffer().clear();
131 else if ( mBuffer.bytesAvailable() > 0 )
133 QByteArray &ba = mBuffer.buffer();
134 size_t count = fwrite( (
void * )ba.data(), ba.size(), 1, FCGI_stdout );
136 qDebug() << QStringLiteral(
"Sent %1 blocks of %2 bytes" ).arg( count ).arg( ba.size() );
150 mBuffer.buffer().clear();
159 return mBuffer.data();
166 mBuffer.buffer().clear();
void setDefaultHeaders()
Set the default headers.
static const QString QGIS_VERSION
Version string.
void truncate() override
Truncate data.
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...
void clear() override
Reset all headers and content for this response.
bool headersSent() const override
Returns true if the headers have already been sent.
QByteArray data() const override
Gets the data written so far.
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::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
void sendError(int code, const QString &message) override
Send error This method delegates error handling at the server level.
void finish() override
Finish the response, ending the transaction.
QgsFcgiServerResponse(QgsServerRequest::Method method=QgsServerRequest::GetMethod)
Constructor for QgsFcgiServerResponse.
void setStatusCode(int code) override
Set the http status code.
void removeHeader(const QString &key) override
Clear header Undo a previous 'setHeader' call.
void flush() override
Flushes the current output buffer to the network.
QIODevice * io() override
Returns the underlying QIODevice.
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...