2016-12-07 22:09:57 +01:00
|
|
|
/***************************************************************************
|
2016-12-14 12:43:00 +01:00
|
|
|
qgsserverresponse.sip
|
2016-12-07 22:09:57 +01:00
|
|
|
|
|
|
|
Define response class for services
|
|
|
|
-------------------
|
|
|
|
begin : 2016-12-05
|
|
|
|
copyright : (C) 2016 by David Marteau
|
|
|
|
email : david dot marteau at 3liz dot com
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \ingroup server
|
|
|
|
* QgsServerResponse
|
|
|
|
* Class defining response interface passed to services QgsService::executeRequest() method
|
|
|
|
*/
|
2016-12-14 12:43:00 +01:00
|
|
|
|
2016-12-07 22:09:57 +01:00
|
|
|
class QgsServerResponse
|
|
|
|
{
|
2017-01-06 21:41:09 +01:00
|
|
|
%TypeHeaderCode
|
2016-12-07 22:09:57 +01:00
|
|
|
#include "qgsserverresponse.h"
|
2017-01-06 21:41:09 +01:00
|
|
|
%End
|
2016-12-14 21:46:00 +01:00
|
|
|
public:
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
//!constructor
|
|
|
|
QgsServerResponse();
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
//! destructor
|
|
|
|
virtual ~QgsServerResponse();
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
/** Set Header entry
|
|
|
|
* Add Header entry to the response
|
|
|
|
* Note that it is usually an error to set Header after writing data
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual void setHeader( const QString &key, const QString &value ) = 0;
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2017-01-04 01:13:14 +01:00
|
|
|
/**
|
|
|
|
* Clear header
|
|
|
|
* Undo a previous 'set_header' call
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual void clearHeader( const QString &key ) = 0;
|
2017-01-04 01:13:14 +01:00
|
|
|
|
2017-01-05 17:40:57 +01:00
|
|
|
/**
|
|
|
|
* Return the header value
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual QString getHeader( const QString &key ) const = 0;
|
2017-01-04 01:13:14 +01:00
|
|
|
|
2017-01-05 17:40:57 +01:00
|
|
|
/**
|
|
|
|
* Return the list of all header keys
|
|
|
|
*/
|
|
|
|
virtual QList<QString> headerKeys() const = 0;
|
|
|
|
|
|
|
|
/**
|
2017-01-07 21:31:26 +01:00
|
|
|
* Return true if the headers have alredy been sent
|
2017-01-05 17:40:57 +01:00
|
|
|
*/
|
2017-01-07 21:31:26 +01:00
|
|
|
virtual bool headersSent() const = 0;
|
2017-01-06 21:10:29 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
/** Set the http return code
|
|
|
|
* @param code HTTP return code value
|
|
|
|
*/
|
|
|
|
virtual void setReturnCode( int code ) = 0;
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
/**
|
|
|
|
* Send error
|
|
|
|
* This method delegates error handling at the server level. This is different
|
|
|
|
* from calling setReturnCode() along with and a specific response body.
|
2016-12-16 17:01:48 +01:00
|
|
|
* @param code HTTP return code value
|
2016-12-14 21:46:00 +01:00
|
|
|
* @param message An informative error message
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual void sendError( int code, const QString &message ) = 0;
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
/**
|
|
|
|
* Write string
|
|
|
|
* This is a convenient method that will write directly
|
|
|
|
* to the underlying I/O device
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual void write( const QString &data );
|
2016-12-14 21:46:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write chunk of data
|
|
|
|
* This is a convenient method that will write directly to the
|
|
|
|
* underlying I/O device
|
|
|
|
* @return the number of bytes that were actually written
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual qint64 write( const QByteArray &byteArray );
|
2016-12-14 21:46:00 +01:00
|
|
|
|
2017-01-11 22:59:27 +01:00
|
|
|
/**
|
|
|
|
* Write server exception
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual void write( const QgsServerException &ex );
|
2017-01-11 22:59:27 +01:00
|
|
|
|
2016-12-14 21:46:00 +01:00
|
|
|
/**
|
|
|
|
* Return the underlying QIODevice
|
|
|
|
*/
|
2017-04-21 13:12:22 +02:00
|
|
|
virtual QIODevice *io() = 0;
|
2016-12-07 22:09:57 +01:00
|
|
|
|
2017-01-04 01:13:14 +01:00
|
|
|
/**
|
|
|
|
* End the transaction
|
|
|
|
*/
|
|
|
|
virtual void finish() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flushes the current output buffer to the network
|
|
|
|
*
|
|
|
|
* 'flush()' may be called multiple times. For HTTP transactions
|
|
|
|
* headers will be written on the first call to 'flush()'.
|
|
|
|
*/
|
|
|
|
virtual void flush() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset all headers and content for this response
|
|
|
|
*/
|
|
|
|
virtual void clear() = 0;
|
|
|
|
|
2017-04-21 13:12:22 +02:00
|
|
|
/**
|
|
|
|
* Get the data written so far
|
|
|
|
*/
|
|
|
|
virtual QByteArray data() const = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Truncate internal buffer
|
|
|
|
*/
|
|
|
|
virtual void truncate() = 0;
|
2016-12-07 22:09:57 +01:00
|
|
|
};
|
|
|
|
|