26using namespace Qt::StringLiterals;
34 mBuffer.open( QIODevice::ReadWrite );
40 mHeaders.remove( key );
47 mHeaders[key] = QList<QString>() << value;
55 if ( !mHeaders.contains( key ) )
57 mHeaders[key] = QList<QString>();
59 mHeaders[key].append( value );
70 const QList<QString> values = mHeaders.value( key );
71 return values.isEmpty() ? QString() : values.last();
76 QMap<QString, QString> singleHeaders;
77 for (
auto it = mHeaders.keyBegin(); it != mHeaders.keyEnd(); ++it )
79 singleHeaders.insert( *it,
header( *it ) );
99 setHeader( u
"Content-Type"_s, u
"text/plain; charset=utf-8"_s );
119 if ( !mHeaders.contains(
"Content-Length" ) )
121 mHeaders.insert( u
"Content-Length"_s, QList<QString>() << QString::number( mBuffer.pos() ) );
136 QByteArray &ba = mBuffer.buffer();
146 mBuffer.buffer().clear();
152 return mBuffer.data();
159 mBuffer.buffer().clear();
165 return mHeaders.value( key );
Q_DECL_DEPRECATED QMap< QString, QString > headers() const override
Returns all the headers as a map: only the last value is returned if multiple values are set for the ...
void setStatusCode(int code) override
Set the http status code.
void flush() override
Flushes the current output buffer to the network.
virtual QList< QString > fullHeader(const QString &key) const override
Returns all the values for a header key.
Q_DECL_DEPRECATED QString header(const QString &key) const override
Returns a single header value, or an empty string if the header is not set.
QgsBufferServerResponse()
QByteArray data() const override
Gets the data written so far.
void addHeader(const QString &key, const QString &value) override
Add a header value for the given key, without replacing any existing value for the same key Add Heade...
void finish() override
Finish the response, ending the transaction.
void sendError(int code, const QString &message) override
Send error This method delegates error handling at the server level.
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 clear() override
Reset all headers and content for this response.
bool headersSent() const override
Returns true if the headers have already been sent.
void truncate() override
Truncate data.
void removeHeader(const QString &key) override
Clear header Undo a previous 'setHeader' call.
QIODevice * io() override
Returns the underlying QIODevice.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.