QGIS API Documentation 3.43.0-Master (b60ef06885e)
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#include "qgsfeedback.h"
26
27#include <QString>
28#include <QIODevice>
29
31
37// Note:
38// This class is intended to be used from Python code: method signatures and return types should be
39// compatible with pyQGIS/pyQT types and rules.
40
41class SERVER_EXPORT QgsServerResponse
42{
43 public:
44 QgsServerResponse() = default;
45 virtual ~QgsServerResponse() = default;
46
52 virtual void setHeader( const QString &key, const QString &value ) = 0;
53
58 virtual void removeHeader( const QString &key ) = 0;
59
63 virtual QString header( const QString &key ) const = 0;
64
68 virtual QMap<QString, QString> headers() const = 0;
69
73 virtual bool headersSent() const = 0;
74
75
80 virtual void setStatusCode( int code ) = 0;
81
85 virtual int statusCode() const = 0;
86
96 virtual void sendError( int code, const QString &message ) = 0;
97
103 virtual void write( const QString &data );
104
111 virtual qint64 write( const QByteArray &byteArray );
112
122 virtual qint64 write( const char *data, qint64 maxsize ) SIP_SKIP;
123
133 virtual qint64 write( const char *data ) SIP_SKIP;
134
144 virtual qint64 write( std::string data ) SIP_SKIP;
145
149 virtual void write( const QgsServerException &ex );
150
154 virtual QIODevice *io() = 0;
155
159 virtual void finish() SIP_THROW( QgsServerException ) SIP_VIRTUALERRORHANDLER( server_exception_handler );
160
168 virtual void flush() SIP_THROW( QgsServerException ) SIP_VIRTUALERRORHANDLER( server_exception_handler );
169
173 virtual void clear() = 0;
174
184 virtual QByteArray data() const = 0;
185
191 virtual void truncate() = 0;
192
197 virtual QgsFeedback *feedback() const;
198};
199
200#endif
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Exception base class for server exceptions.
Defines the response interface passed to QgsService.
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
virtual QMap< QString, QString > headers() const =0
Returns the header value.
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...
QgsServerResponse()=default
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_SKIP
Definition qgis_sip.h:126
#define SIP_VIRTUALERRORHANDLER(name)
Definition qgis_sip.h:196
#define SIP_THROW(name,...)
Definition qgis_sip.h:203