QGIS API Documentation 4.1.0-Master (31622b25bb0)
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:
41
47 void setHeader( const QString &key, const QString &value ) override;
48
55 void addHeader( const QString &key, const QString &value ) override;
56
61 void removeHeader( const QString &key ) override;
62
68 Q_DECL_DEPRECATED QString header( const QString &key ) const override SIP_DEPRECATED;
69
73 QMap<QString, QList<QString>> fullHeaders() const override { return mHeaders; }
74
78 virtual QList<QString> fullHeader( const QString &key ) const override;
79
84 Q_DECL_DEPRECATED QMap<QString, QString> headers() const override SIP_DEPRECATED;
85
89 bool headersSent() const override;
90
95 void setStatusCode( int code ) override;
96
100 int statusCode() const override { return mStatusCode; }
101
111 void sendError( int code, const QString &message ) override;
112
116 QIODevice *io() override;
117
121 void finish() override;
122
129 void flush() override;
130
134 void clear() override;
135
145 QByteArray data() const override;
146
152 void truncate() override;
153
157 QByteArray body() const { return mBody; }
158
159
160 private:
161#ifdef SIP_RUN
163#endif
164
165 QMap<QString, QList<QString>> mHeaders;
166 QBuffer mBuffer;
167 QByteArray mBody;
168 bool mFinished = false;
169 bool mHeadersSent = false;
170 int mStatusCode = 200;
171};
172
173#endif
Defines a buffered server response.
QMap< QString, QList< QString > > fullHeaders() const override
Returns all the headers.
QgsBufferServerResponse(const QgsBufferServerResponse &)=delete
QByteArray body() const
Returns body.
int statusCode() const override
Returns the http status code.
virtual void removeHeader(const QString &key)=0
Clear all header values for the given key Undo a previous 'setHeader' call.
virtual void truncate()=0
Truncate data.
virtual void flush()
Flushes the current output buffer to the network.
virtual Q_DECL_DEPRECATED QString header(const QString &key) const =0
Returns a single header value for a given key.
virtual QList< QString > fullHeader(const QString &key) const =0
Returns a (possibly empty) list of all the header values for the given key.
virtual Q_DECL_DEPRECATED QMap< QString, QString > headers() const =0
Returns the header values as a map: only the last value is returned if multiple values are set for th...
virtual QByteArray data() const =0
Gets the data written so far.
virtual void setHeader(const QString &key, const QString &value)=0
Set a single header value replacing any existing value(s) for the same key.
virtual void addHeader(const QString &key, const QString &value)=0
Add a header value for the given key, without replacing any existing value for the same key Add Heade...
virtual void clear()=0
Reset all headers and content for this response.
QgsServerResponse()=default
virtual void finish()
Finish the response, ending the transaction.
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.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_FORCE
Definition qgis_sip.h:138