QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 "qgis_server.h"
23#include "qgsserverparameters.h"
24
25#include <QMap>
26#include <QUrl>
27
28// Note about design: this interface must be passed along to Python and thus signatures methods must be
29// compatible with pyQGIS/pyQT api and rules.
30
35class SERVER_EXPORT QgsServerRequest
36{
37 Q_GADGET
38
39 public:
40 typedef QMap<QString, QString> Parameters;
41 typedef QMap<QString, QString> Headers;
42
55 Q_ENUM( Method )
56
57
77 Q_ENUM( RequestHeader )
78
79 QgsServerRequest() = default;
80
89
98
99 QgsServerRequest( const QgsServerRequest &other );
100
101 QgsServerRequest &operator=( const QgsServerRequest & ) = default;
102 virtual ~QgsServerRequest() = default;
103
108 static QString methodToString( const Method &method );
109
110
116 QUrl url() const;
117
122
128
133
137 virtual void setParameter( const QString &key, const QString &value );
138
142 QString parameter( const QString &key, const QString &defaultValue = QString() ) const;
143
147 virtual void removeParameter( const QString &key );
148
154 virtual QString header( const QString &name ) const;
155
161 virtual QString header( const RequestHeader &headerEnum ) const;
162
168 void setHeader( const QString &name, const QString &value );
169
174 QMap<QString, QString> headers() const;
175
181 void removeHeader( const QString &name );
182
188 virtual QByteArray data() const;
189
193 virtual void setUrl( const QUrl &url );
194
202 QUrl originalUrl() const;
203
212 QUrl baseUrl() const;
213
218
223 const QString queryParameter( const QString &name, const QString &defaultValue = QString() ) const;
224
225 protected:
226
233 void setOriginalUrl( const QUrl &url );
234
240 void setBaseUrl( const QUrl &url );
241
242 private:
243 // Url as seen by QGIS server after web server rewrite
244 QUrl mUrl;
245 // Unrewritten url as seen by the web server
246 QUrl mOriginalUrl;
247 QUrl mBaseUrl;
248 Method mMethod = GetMethod;
249 // We mark as mutable in order
250 // to support lazy initialization
251 mutable Headers mHeaders;
252 QgsServerParameters mParams;
253};
254
255#endif
Provides an interface to retrieve and manipulate global parameters received from the client.
void setOriginalUrl(const QUrl &url)
Set the request original url (the request url as seen by the web server).
Method
HTTP Method (or equivalent) used for the request.
QgsServerParameters serverParameters() const
Returns parameters.
const QString queryParameter(const QString &name, const QString &defaultValue=QString()) const
Returns the query string parameter with the given name from the request URL, a defaultValue can be sp...
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.
virtual QString header(const QString &name) const
Returns the header value.
QString parameter(const QString &key, const QString &defaultValue=QString()) const
Gets a parameter value.
virtual void setParameter(const QString &key, const QString &value)
Set a parameter.
QgsServerRequest()=default
virtual void setUrl(const QUrl &url)
Set the request url.
QUrl url() const
Returns the request URL as seen by QGIS server.
QMap< QString, QString > headers() const
Returns the header map.
QUrl baseUrl() const
Returns the base URL of QGIS server.
QMap< QString, QString > Parameters
QgsServerRequest::Method method() const
Returns the request method.
QUrl originalUrl() const
Returns the request url as seen by the web server, by default this is equal to the url seen by QGIS s...
void setMethod(QgsServerRequest::Method method)
Set the request method.
void removeHeader(const QString &name)
Remove an header.
QMap< QString, QString > Headers
virtual void removeParameter(const QString &key)
Remove a parameter.
void setBaseUrl(const QUrl &url)
Set the base URL of QGIS server.
void setHeader(const QString &name, const QString &value)
Set an header.
RequestHeader
The internal HTTP Header used for the request as enum.
@ X_QGIS_WMS_SERVICE_URL
The QGIS WMS service URL.
@ ACCEPT
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept.
@ X_QGIS_WCS_SERVICE_URL
The QGIS WCS service URL.
@ USER_AGENT
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent.
@ X_QGIS_WFS_SERVICE_URL
The QGIS WFS service URL.
@ X_FORWARDED_FOR
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For.
@ X_FORWARDED_PROTO
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto.
@ X_QGIS_WMTS_SERVICE_URL
The QGIS WMTS service URL.
@ X_QGIS_SERVICE_URL
The QGIS service URL.
@ X_FORWARDED_HOST
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host.
@ FORWARDED
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded, https://tools....
@ HOST
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host.
@ AUTHORIZATION
Https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization.
static QString methodToString(const Method &method)
Returns a string representation of an HTTP request method.
virtual QByteArray data() const
Returns post/put data Check for QByteArray::isNull() to check if data is available.