Skip to content

Commit 2adbaf0

Browse files
committed
Add parameter map accessor from QgsServerRequest
1 parent ec226ee commit 2adbaf0

File tree

4 files changed

+50
-14
lines changed

4 files changed

+50
-14
lines changed

python/server/qgsserverrequest.sip

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class QgsServerRequest
3030
%End
3131
public:
3232

33-
enum Method {
33+
enum Method
34+
{
3435
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod
3536
};
3637

@@ -61,12 +62,17 @@ class QgsServerRequest
6162
/**
6263
* @return the request url
6364
*/
64-
virtual QUrl url() const;
65+
QUrl url() const;
6566

6667
/**
6768
* @return the request method
6869
*/
69-
virtual Method method() const;
70+
Method method() const;
71+
72+
/**
73+
* * @return query params
74+
* */
75+
QMap<QString, QString> parameters() const;
7076

7177
/**
7278
* Return post/put data

src/server/qgsserverrequest.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
***************************************************************************/
1919

2020
#include "qgsserverrequest.h"
21-
21+
#include <QUrlQuery>
2222

2323
QgsServerRequest::QgsServerRequest( const QString& url, Method method )
2424
: mUrl( url )
@@ -56,6 +56,23 @@ QgsServerRequest::Method QgsServerRequest::method() const
5656
return mMethod;
5757
}
5858

59+
QMap<QString, QString> QgsServerRequest::parameters() const
60+
{
61+
// Lazy build of the parameter map
62+
if ( mParams.isEmpty() && mUrl.hasQuery() )
63+
{
64+
typedef QPair<QString, QString> pair_t;
65+
66+
QUrlQuery query( mUrl );
67+
QList<pair_t> items = query.queryItems();
68+
Q_FOREACH ( const pair_t& pair, items )
69+
{
70+
mParams.insert( pair.first.toUpper(), pair.second );
71+
}
72+
}
73+
return mParams;
74+
}
75+
5976
QByteArray QgsServerRequest::data() const
6077
{
6178
return QByteArray();

src/server/qgsserverrequest.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define QGSSERVERREQUEST_H
2121

2222
#include <QUrl>
23+
#include <QMap>
2324

2425
/**
2526
* \ingroup server
@@ -58,20 +59,21 @@ class SERVER_EXPORT QgsServerRequest
5859
//! destructor
5960
virtual ~QgsServerRequest();
6061

61-
/**
62-
* @return the value of the header field for that request
63-
*/
64-
virtual QString getHeader( const QString& name ) const;
65-
6662
/**
6763
* @return the request url
6864
*/
69-
virtual QUrl url() const;
65+
QUrl url() const;
7066

7167
/**
7268
* @return the request method
7369
*/
74-
virtual Method method() const;
70+
Method method() const;
71+
72+
/**
73+
* Return a map of query parameters with keys converted
74+
* to uppercase
75+
*/
76+
QMap<QString, QString> parameters() const;
7577

7678
/**
7779
* Return post/put data
@@ -80,10 +82,19 @@ class SERVER_EXPORT QgsServerRequest
8082
*/
8183
virtual QByteArray data() const;
8284

83-
protected:
84-
QUrl mUrl;
85-
Method mMethod;
85+
/**
86+
* @return the value of the header field for that request
87+
*/
88+
virtual QString getHeader( const QString& name ) const;
8689

90+
private:
91+
QUrl mUrl;
92+
Method mMethod;
93+
// We mark as mutable in order
94+
// to support lazy initialization
95+
// Use QMap here because it will be faster for small
96+
// number of elements
97+
mutable QMap<QString, QString> mParams;
8798
};
8899

89100
#endif

src/server/qgsserviceregistry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class SERVER_EXPORT QgsServiceRegistry
9898
void cleanUp();
9999

100100
private:
101+
// XXX consider using QMap because of the few numbers of
102+
// elements to handle
101103
typedef QHash<QString, std::shared_ptr<QgsService> > ServiceTable;
102104
typedef QHash<QString, QPair<QString, QString> > VersionTable;
103105

0 commit comments

Comments
 (0)