QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsserverrequest.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsserverrequest.cpp
3 
4  Define ruquest 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 
20 #include "qgsserverrequest.h"
21 #include <QUrlQuery>
22 
23 QgsServerRequest::QgsServerRequest( const QString &url, Method method, const Headers &headers )
24  : QgsServerRequest( QUrl( url ), method, headers )
25 {
26 }
27 
29  : mUrl( url )
30  , mOriginalUrl( url )
31  , mMethod( method )
32  , mHeaders( headers )
33 {
34  mParams.load( QUrlQuery( url ) );
35 }
36 
37 QString QgsServerRequest::header( const QString &name ) const
38 {
39  return mHeaders.value( name );
40 }
41 
42 
43 void QgsServerRequest::setHeader( const QString &name, const QString &value )
44 {
45  mHeaders.insert( name, value );
46 }
47 
48 QMap<QString, QString> QgsServerRequest::headers() const
49 {
50  return mHeaders;
51 }
52 
53 
54 void QgsServerRequest::removeHeader( const QString &name )
55 {
56  mHeaders.remove( name );
57 }
58 
60 {
61  return mUrl;
62 }
63 
65 {
66  return mOriginalUrl;
67 }
68 
70 {
71  mOriginalUrl = url;
72 }
73 
75 {
76  return mMethod;
77 }
78 
79 QMap<QString, QString> QgsServerRequest::parameters() const
80 {
81  return mParams.toMap();
82 }
83 
85 {
86  return mParams;
87 }
88 
89 QByteArray QgsServerRequest::data() const
90 {
91  return QByteArray();
92 }
93 
94 void QgsServerRequest::setParameter( const QString &key, const QString &value )
95 {
96  mParams.add( key, value );
97  mUrl.setQuery( mParams.urlQuery() );
98 }
99 
100 QString QgsServerRequest::parameter( const QString &key ) const
101 {
102  return mParams.value( key );
103 }
104 
105 void QgsServerRequest::removeParameter( const QString &key )
106 {
107  mParams.remove( key );
108  mUrl.setQuery( mParams.urlQuery() );
109 }
110 
111 void QgsServerRequest::setUrl( const QUrl &url )
112 {
113  mUrl = url;
114  mParams.clear();
115  mParams.load( QUrlQuery( mUrl ) );
116 }
117 
119 {
120  mMethod = method;
121 }
QgsServerRequest()=default
Constructor.
void setMethod(QgsServerRequest::Method method)
Set the request method.
void setParameter(const QString &key, const QString &value)
Set a parameter.
QMap< QString, QString > toMap() const
Returns all parameters in a map.
QString value(const QString &key) const
Returns the value of a parameter.
void remove(const QString &key)
Removes a parameter.
void load(const QUrlQuery &query)
Loads new parameters.
void setUrl(const QUrl &url)
Set the request url.
Method
HTTP Method (or equivalent) used for the request.
QMap< QString, QString > Headers
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...
QMap< QString, QString > headers() const
Returns the header map.
QString parameter(const QString &key) const
Gets a parameter value.
QgsServerParameters serverParameters() const
Returns parameters.
virtual QByteArray data() const
Returns post/put data Check for QByteArray::isNull() to check if data is available.
QString header(const QString &name) const
Returns the header value.
void setHeader(const QString &name, const QString &value)
Set an header.
QgsServerRequest::Method method() const
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
void add(const QString &key, const QString &value)
Adds a parameter.
void removeHeader(const QString &name)
Remove an header.
QgsServerParameters provides an interface to retrieve and manipulate global parameters received from ...
QUrlQuery urlQuery() const
Returns a url query with underlying parameters.
void removeParameter(const QString &key)
Remove a parameter.
void setOriginalUrl(const QUrl &url)
Set the request original url (the request url as seen by the web server)
void clear()
Removes all parameters.
QgsServerRequest::Parameters parameters() const
Returns a map of query parameters with keys converted to uppercase.