QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsserverrequest.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverrequest.h
3 
4  Define request class for getting request contents
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 QGSSERVERREQUEST_H
20 #define QGSSERVERREQUEST_H
21 
22 #include <QUrl>
23 #include <QMap>
24 #include "qgis_server.h"
25 #include "qgsserverparameters.h"
26 
35 // Note about design: this interface must be passed along to Python and thus signatures methods must be
36 // compatible with pyQGIS/pyQT api and rules.
37 
38 class SERVER_EXPORT QgsServerRequest
39 {
40  Q_GADGET
41 
42  public:
43 
44  typedef QMap<QString, QString> Parameters;
45  typedef QMap<QString, QString> Headers;
46 
50  enum Method
51  {
57  PatchMethod
58  };
59  Q_ENUM( Method )
60 
61 
65  {
66  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
68  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
69  // https://tools.ietf.org/html/rfc7239
71  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
73  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
75  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
77  // The QGIS service URL
79  // The QGIS WMS service URL
81  // The QGIS WFS service URL
83  // The QGIS WCS service URL
85  // The QGIS WMTS service URL
87  };
88  Q_ENUM( RequestHeader )
89 
90 
93  QgsServerRequest() = default;
94 
102  QgsServerRequest( const QString &url, QgsServerRequest::Method method = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers() );
103 
111  QgsServerRequest( const QUrl &url, QgsServerRequest::Method method = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers() );
112 
116  QgsServerRequest( const QgsServerRequest &other );
117 
118  QgsServerRequest &operator=( const QgsServerRequest & ) = default;
119 
121  virtual ~QgsServerRequest() = default;
122 
127  static QString methodToString( const Method &method );
128 
129 
136  QUrl url() const;
137 
141  QgsServerRequest::Method method() const;
142 
147  QgsServerRequest::Parameters parameters() const;
148 
152  QgsServerParameters serverParameters() const;
153 
157  virtual void setParameter( const QString &key, const QString &value );
158 
162  QString parameter( const QString &key, const QString &defaultValue = QString() ) const;
163 
167  virtual void removeParameter( const QString &key );
168 
174  virtual QString header( const QString &name ) const;
175 
181  virtual QString header( const RequestHeader &headerEnum ) const;
182 
188  void setHeader( const QString &name, const QString &value );
189 
194  QMap<QString, QString> headers() const;
195 
201  void removeHeader( const QString &name );
202 
208  virtual QByteArray data() const;
209 
213  virtual void setUrl( const QUrl &url );
214 
222  QUrl originalUrl() const;
223 
232  QUrl baseUrl() const;
233 
237  void setMethod( QgsServerRequest::Method method );
238 
243  const QString queryParameter( const QString &name, const QString &defaultValue = QString( ) ) const;
244 
245  protected:
246 
253  void setOriginalUrl( const QUrl &url );
254 
260  void setBaseUrl( const QUrl &url );
261 
262  private:
263  // Url as seen by QGIS server after web server rewrite
264  QUrl mUrl;
265  // Unrewritten url as seen by the web server
266  QUrl mOriginalUrl;
267  QUrl mBaseUrl;
268  Method mMethod = GetMethod;
269  // We mark as mutable in order
270  // to support lazy initialization
271  mutable Headers mHeaders;
272  QgsServerParameters mParams;
273  QMap<RequestHeader, QString> mRequestHeaderConv;
274 };
275 
276 #endif
QgsServerParameters provides an interface to retrieve and manipulate global parameters received from ...
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Method
HTTP Method (or equivalent) used for the request.
QMap< QString, QString > Parameters
QMap< QString, QString > Headers
RequestHeader
The internal HTTP Header used for the request as enum.