QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsserverresponse.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverresponse.h
3 
4  Define response class for services
5  -------------------
6  begin : 2016-12-05
7  copyright : (C) 2016 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 QGSSERVERRESPONSE_H
20 #define QGSSERVERRESPONSE_H
21 
22 #include "qgis_server.h"
23 #include "qgis_sip.h"
24 #include "qgsserverexception.h"
25 
26 #include <QString>
27 #include <QIODevice>
28 
29 class QgsServerException;
30 
39 // Note:
40 // This class is intended to be used from Python code: method signatures and return types should be
41 // compatible with pyQGIS/pyQT types and rules.
42 
43 class SERVER_EXPORT QgsServerResponse
44 {
45  public:
46 
48  QgsServerResponse() = default;
49 
51  virtual ~QgsServerResponse() = default;
52 
58  virtual void setHeader( const QString &key, const QString &value ) = 0;
59 
64  virtual void removeHeader( const QString &key ) = 0;
65 
69  virtual QString header( const QString &key ) const = 0;
70 
74  virtual QMap<QString, QString> headers() const = 0;
75 
79  virtual bool headersSent() const = 0;
80 
81 
86  virtual void setStatusCode( int code ) = 0;
87 
91  virtual int statusCode() const = 0;
92 
102  virtual void sendError( int code, const QString &message ) = 0;
103 
109  virtual void write( const QString &data );
110 
117  virtual qint64 write( const QByteArray &byteArray );
118 
128  virtual qint64 write( const char *data, qint64 maxsize ) SIP_SKIP;
129 
139  virtual qint64 write( const char *data ) SIP_SKIP;
140 
150  virtual qint64 write( std::string data ) SIP_SKIP;
151 
155  virtual void write( const QgsServerException &ex );
156 
160  virtual QIODevice *io() = 0;
161 
165  virtual void finish() SIP_THROW( QgsServerException ) SIP_VIRTUALERRORHANDLER( server_exception_handler );
166 
174  virtual void flush() SIP_THROW( QgsServerException ) SIP_VIRTUALERRORHANDLER( server_exception_handler );
175 
179  virtual void clear() = 0;
180 
190  virtual QByteArray data() const = 0;
191 
197  virtual void truncate() = 0;
198 };
199 
200 #endif
Exception base class for server exceptions.
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 int statusCode() const =0
Returns the http status code.
virtual ~QgsServerResponse()=default
destructor
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 QIODevice * io()=0
Returns the underlying QIODevice.
QgsServerResponse()=default
constructor
virtual QMap< QString, QString > headers() const =0
Returns the header value.
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 QString header(const QString &key) const =0
Returns the header value.
virtual void setStatusCode(int code)=0
Set the http status code.
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_VIRTUALERRORHANDLER(name)
Definition: qgis_sip.h:182