QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsbufferserverresponse.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsbufferserverresponse.h
3
4 Define response wrapper for storing responsea in buffer
5 -------------------
6 begin : 2017-01-03
7 copyright : (C) 2017 by David Marteau
8 email : david dot marteau at 3liz dot com
9 ***************************************************************************/
10
11/***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19#ifndef QGSBUFFERSERVERRESPONSE_H
20#define QGSBUFFERSERVERRESPONSE_H
21
22#include "qgis_server.h"
23#include "qgis_sip.h"
24#include "qgsserverresponse.h"
25
26#include <QBuffer>
27#include <QByteArray>
28#include <QMap>
29#include <QString>
30
36class SERVER_EXPORT QgsBufferServerResponse: public QgsServerResponse
37{
38 public:
39
42
48 void setHeader( const QString &key, const QString &value ) override;
49
54 void removeHeader( const QString &key ) override;
55
59 QString header( const QString &key ) const override;
60
64 QMap<QString, QString> headers() const override { return mHeaders; }
65
69 bool headersSent() const override;
70
75 void setStatusCode( int code ) override;
76
80 int statusCode() const override { return mStatusCode; }
81
91 void sendError( int code, const QString &message ) override;
92
96 QIODevice *io() override;
97
101 void finish() override;
102
109 void flush() override;
110
114 void clear() override;
115
125 QByteArray data() const override;
126
132 void truncate() override;
133
137 QByteArray body() const { return mBody; }
138
139
140 private:
141
142#ifdef SIP_RUN
144#endif
145
146 QMap<QString, QString> mHeaders;
147 QBuffer mBuffer;
148 QByteArray mBody;
149 bool mFinished = false;
150 bool mHeadersSent = false;
151 int mStatusCode = 200;
152};
153
154#endif
Class defining buffered response.
QMap< QString, QString > headers() const override
Returns all the headers.
QgsBufferServerResponse(const QgsBufferServerResponse &)=delete
QByteArray body() const
Returns body.
int statusCode() const override
Returns the http status code.
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
virtual void removeHeader(const QString &key)=0
Clear header Undo a previous 'setHeader' call.
virtual void truncate()=0
Truncate data.
virtual void flush()
Flushes the current output buffer to the network.
virtual QByteArray data() const =0
Gets the data written so far.
virtual void setHeader(const QString &key, const QString &value)=0
Set Header entry Add Header entry to the response Note that it is usually an error to set Header afte...
virtual void clear()=0
Reset all headers and content for this response.
virtual void finish()
Finish the response, ending the transaction.
virtual bool headersSent() const =0
Returns true if the headers have already been sent.
virtual void sendError(int code, const QString &message)=0
Send error This method delegates error handling at the server level.
virtual QIODevice * io()=0
Returns the underlying QIODevice.
virtual QString header(const QString &key) const =0
Returns the header value.
virtual void setStatusCode(int code)=0
Set the http status code.
#define SIP_FORCE
Definition qgis_sip.h:131