QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
37 class SERVER_EXPORT QgsBufferServerResponse: public QgsServerResponse
38 {
39  public:
40 
42 
45 
51  void setHeader( const QString &key, const QString &value ) override;
52 
57  void removeHeader( const QString &key ) override;
58 
62  QString header( const QString &key ) const override;
63 
67  QMap<QString, QString> headers() const override { return mHeaders; }
68 
72  bool headersSent() const override;
73 
78  void setStatusCode( int code ) override;
79 
83  int statusCode() const override { return mStatusCode; }
84 
94  void sendError( int code, const QString &message ) override;
95 
99  QIODevice *io() override;
100 
104  void finish() override;
105 
112  void flush() override;
113 
117  void clear() override;
118 
128  QByteArray data() const override;
129 
135  void truncate() override;
136 
140  QByteArray body() const { return mBody; }
141 
142 
143  private:
144 
145 #ifdef SIP_RUN
147 #endif
148 
149  QMap<QString, QString> mHeaders;
150  QBuffer mBuffer;
151  QByteArray mBody;
152  bool mFinished = false;
153  bool mHeadersSent = false;
154  int mStatusCode = 200;
155 };
156 
157 #endif
QgsBufferServerResponse
Class defining buffered response.
Definition: qgsbufferserverresponse.h:38
QgsServerResponse::flush
virtual void flush() SIP_THROW(QgsServerException)
Flushes the current output buffer to the network.
Definition: qgsserverresponse.cpp:73
QgsServerResponse::truncate
virtual void truncate()=0
Truncate data.
QgsServerResponse::clear
virtual void clear()=0
Reset all headers and content for this response.
QgsBufferServerResponse::QgsBufferServerResponse
QgsBufferServerResponse(const QgsBufferServerResponse &)=delete
QgsBufferServerResponse cannot be copied.
qgsserverresponse.h
QgsServerResponse::header
virtual QString header(const QString &key) const =0
Returns the header value.
QgsServerResponse::setStatusCode
virtual void setStatusCode(int code)=0
Set the http status code.
QgsServerResponse::removeHeader
virtual void removeHeader(const QString &key)=0
Clear header Undo a previous 'setHeader' call.
qgis_sip.h
QgsBufferServerResponse::headers
QMap< QString, QString > headers() const override
Returns all the headers.
Definition: qgsbufferserverresponse.h:67
QgsBufferServerResponse::body
QByteArray body() const
Returns body.
Definition: qgsbufferserverresponse.h:140
QgsServerResponse::data
virtual QByteArray data() const =0
Gets the data written so far.
QgsBufferServerResponse::statusCode
int statusCode() const override
Returns the http status code.
Definition: qgsbufferserverresponse.h:83
QgsServerResponse::headersSent
virtual bool headersSent() const =0
Returns true if the headers have already been sent.
SIP_FORCE
#define SIP_FORCE
Definition: qgis_sip.h:131
QgsServerResponse::finish
virtual void finish() SIP_THROW(QgsServerException)
Finish the response, ending the transaction.
Definition: qgsserverresponse.cpp:68
QgsServerResponse::io
virtual QIODevice * io()=0
Returns the underlying QIODevice.
QgsServerResponse::sendError
virtual void sendError(int code, const QString &message)=0
Send error This method delegates error handling at the server level.
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:44
QgsServerResponse::setHeader
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...