-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsrequesthandler.h
163 lines (123 loc) · 4.92 KB
/
qgsrequesthandler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/***************************************************************************
qgshttprequesthandler.h
-----------------------
begin : June 29, 2007
copyright : (C) 2007 by Marco Hugentobler
(C) 2014 by Alessandro Pasotti
email : marco dot hugentobler at karto dot baug dot ethz dot ch
a dot pasotti at itopen dot it
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef QGSREQUESTHANDLER_H
#define QGSREQUESTHANDLER_H
#include <QMap>
#include "qgis_sip.h"
#include <QString>
#include "qgis_server.h"
class QgsServerException;
class QgsServerRequest;
class QgsServerResponse;
/**
* \ingroup server
* \brief This class is an interface hiding the details of reading input and writing
* output from/to a wms request mechanism.
*/
class SERVER_EXPORT QgsRequestHandler
{
public:
/**
* Constructor
*
* Note that QgsServerRequest and QgsServerResponse MUST live in the same scope
*/
explicit QgsRequestHandler( QgsServerRequest &request, QgsServerResponse &response );
//! Allow plugins to return a QgsMapServiceException
void setServiceException( const QgsServerException &ex );
/**
* Send out HTTP headers and flush output buffer
*
* This method is intended only for streaming
* partial content.
*/
void sendResponse();
//! Sets an HTTP response header
void setResponseHeader( const QString &name, const QString &value );
//! Remove an HTTP response header
void removeResponseHeader( const QString &name );
//! Retrieve response header value
QString responseHeader( const QString &name ) const;
//! Returns the response headers
QMap<QString, QString> responseHeaders() const;
//! Sets an HTTP request header
void setRequestHeader( const QString &name, const QString &value );
//! Remove an HTTP request header
void removeRequestHeader( const QString &name );
//! Retrieve request header value
QString requestHeader( const QString &name ) const;
//! Returns the the Request headers
QMap<QString, QString> requestHeaders() const;
//! Clears the response body and headers
void clear();
//! Sets the info format string such as "text/xml"
void appendBody( const QByteArray &body );
//! Pointer to last raised exception
bool exceptionRaised() const;
//! Clear response buffer
void clearBody();
//! Returns the response body data
QByteArray body() const;
//! Returns the request POST data (can be null)
QByteArray data() const;
//! Returns the request url
QString url() const;
/**
* Returns the path component of the request URL
* \since QGIS 3.16
*/
QString path() const;
//! Sets response http status code
void setStatusCode( int code );
//! Returns the response http status code
int statusCode() const;
/**
* Returns the parsed parameters as a key-value pair, to modify
* a parameter setParameter( const QString &key, const QString &value)
* and removeParameter(const QString &key) must be used
*/
QMap<QString, QString> parameterMap() const;
//! Sets a request parameter
void setParameter( const QString &key, const QString &value );
//! Returns a request parameter
QString parameter( const QString &key ) const;
//! Remove a request parameter
void removeParameter( const QString &key );
/**
* Parses the input and creates a request neutral Parameter/Value map
* \note not available in Python bindings
*/
void parseInput() SIP_SKIP;
//! Returns the requested format string
QString format() const { return mFormat; }
//! Returns TRUE if the HTTP headers were already sent to the client
bool headersSent() const;
private:
#ifdef SIP_RUN
QgsRequestHandler &operator=( const QgsRequestHandler & );
#endif
void setupParameters();
//! This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')
QString mFormat;
QString mFormatString; //format string as it is passed in the request (with base)
QString mService;
bool mExceptionRaised;
QgsServerRequest &mRequest;
QgsServerResponse &mResponse;
};
#endif