QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
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 "qgsfeedback.h"
25#include "qgsserverexception.h"
26
27#include <QIODevice>
28#include <QString>
29
31
36
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
53 virtual void setHeader( const QString &key, const QString &value ) = 0;
54
62 virtual void addHeader( const QString &key, const QString &value ) = 0;
63
68 virtual void removeHeader( const QString &key ) = 0;
69
75 Q_DECL_DEPRECATED virtual QString header( const QString &key ) const = 0 SIP_DEPRECATED;
76
82 virtual QList<QString> fullHeader( const QString &key ) const = 0;
83
89 Q_DECL_DEPRECATED virtual QMap<QString, QString> headers() const = 0 SIP_DEPRECATED;
90
96 virtual QMap<QString, QList<QString>> fullHeaders() const = 0;
97
101 virtual bool headersSent() const = 0;
102
107 virtual void setStatusCode( int code ) = 0;
108
112 virtual int statusCode() const = 0;
113
123 virtual void sendError( int code, const QString &message ) = 0;
124
130 virtual void write( const QString &data );
131
138 virtual qint64 write( const QByteArray &byteArray );
139
149 virtual qint64 write( const char *data, qint64 maxsize ) SIP_SKIP;
150
160 virtual qint64 write( const char *data ) SIP_SKIP;
161
171 virtual qint64 write( std::string data ) SIP_SKIP;
172
176 virtual void write( const QgsServerException &ex );
177
181 virtual QIODevice *io() = 0;
182
186 virtual void finish() SIP_THROW( QgsServerException ) SIP_VIRTUALERRORHANDLER( server_exception_handler );
187
195 virtual void flush() SIP_THROW( QgsServerException ) SIP_VIRTUALERRORHANDLER( server_exception_handler );
196
200 virtual void clear() = 0;
201
211 virtual QByteArray data() const = 0;
212
218 virtual void truncate() = 0;
219
224 virtual QgsFeedback *feedback() const;
225};
226
227#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.
virtual void write(const QString &data)
Write string This is a convenient method that will write directly to the underlying I/O device.
virtual void removeHeader(const QString &key)=0
Clear all header values for the given key Undo a previous 'setHeader' call.
virtual int statusCode() const =0
Returns the http status code.
virtual void truncate()=0
Truncate data.
virtual ~QgsServerResponse()=default
virtual void flush()
Flushes the current output buffer to the network.
virtual QMap< QString, QList< QString > > fullHeaders() const =0
Returns all the header values.
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 QgsFeedback * feedback() const
Returns the socket feedback if any.
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 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 void setStatusCode(int code)=0
Set the http status code.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_VIRTUALERRORHANDLER(name)
Definition qgis_sip.h:203
#define SIP_THROW(name,...)
Definition qgis_sip.h:210