QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  {
52  HeadMethod,
53  PutMethod,
54  GetMethod,
55  PostMethod,
56  DeleteMethod,
57  PatchMethod
58  };
59  Q_ENUM( Method )
60 
61 
64  enum RequestHeader
65  {
66  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
67  HOST,
68  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
69  // https://tools.ietf.org/html/rfc7239
70  FORWARDED,
71  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
72  X_FORWARDED_FOR,
73  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
74  X_FORWARDED_HOST,
75  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
76  X_FORWARDED_PROTO,
77  // The QGIS service URL
78  X_QGIS_SERVICE_URL,
79  // The QGIS WMS service URL
80  X_QGIS_WMS_SERVICE_URL,
81  // The QGIS WFS service URL
82  X_QGIS_WFS_SERVICE_URL,
83  // The QGIS WCS service URL
84  X_QGIS_WCS_SERVICE_URL,
85  // The QGIS WMTS service URL
86  X_QGIS_WMTS_SERVICE_URL,
87  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept
88  ACCEPT,
89  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
90  USER_AGENT,
91  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
92  AUTHORIZATION,
93  };
94  Q_ENUM( RequestHeader )
95 
96 
99  QgsServerRequest() = default;
100 
108  QgsServerRequest( const QString &url, QgsServerRequest::Method method = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers() );
109 
117  QgsServerRequest( const QUrl &url, QgsServerRequest::Method method = QgsServerRequest::GetMethod, const QgsServerRequest::Headers &headers = QgsServerRequest::Headers() );
118 
122  QgsServerRequest( const QgsServerRequest &other );
123 
124  QgsServerRequest &operator=( const QgsServerRequest & ) = default;
125 
127  virtual ~QgsServerRequest() = default;
128 
133  static QString methodToString( const Method &method );
134 
135 
142  QUrl url() const;
143 
147  QgsServerRequest::Method method() const;
148 
153  QgsServerRequest::Parameters parameters() const;
154 
158  QgsServerParameters serverParameters() const;
159 
163  virtual void setParameter( const QString &key, const QString &value );
164 
168  QString parameter( const QString &key, const QString &defaultValue = QString() ) const;
169 
173  virtual void removeParameter( const QString &key );
174 
180  virtual QString header( const QString &name ) const;
181 
187  virtual QString header( const RequestHeader &headerEnum ) const;
188 
194  void setHeader( const QString &name, const QString &value );
195 
200  QMap<QString, QString> headers() const;
201 
207  void removeHeader( const QString &name );
208 
214  virtual QByteArray data() const;
215 
219  virtual void setUrl( const QUrl &url );
220 
228  QUrl originalUrl() const;
229 
238  QUrl baseUrl() const;
239 
243  void setMethod( QgsServerRequest::Method method );
244 
249  const QString queryParameter( const QString &name, const QString &defaultValue = QString( ) ) const;
250 
251  protected:
252 
259  void setOriginalUrl( const QUrl &url );
260 
266  void setBaseUrl( const QUrl &url );
267 
268  private:
269  // Url as seen by QGIS server after web server rewrite
270  QUrl mUrl;
271  // Unrewritten url as seen by the web server
272  QUrl mOriginalUrl;
273  QUrl mBaseUrl;
274  Method mMethod = GetMethod;
275  // We mark as mutable in order
276  // to support lazy initialization
277  mutable Headers mHeaders;
278  QgsServerParameters mParams;
279 };
280 
281 #endif
qgsserverparameters.h
QgsServerRequest
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Definition: qgsserverrequest.h:38
QgsServerRequest::Parameters
QMap< QString, QString > Parameters
Definition: qgsserverrequest.h:59
QgsServerRequest::RequestHeader
RequestHeader
The internal HTTP Header used for the request as enum.
Definition: qgsserverrequest.h:79
QgsServerRequest::Method
Method
HTTP Method (or equivalent) used for the request.
Definition: qgsserverrequest.h:65
QgsServerRequest::Headers
QMap< QString, QString > Headers
Definition: qgsserverrequest.h:60
QgsServerParameters
QgsServerParameters provides an interface to retrieve and manipulate global parameters received from ...
Definition: qgsserverparameters.h:242