mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Add parameter map accessor from QgsServerRequest
This commit is contained in:
parent
ec226eeab8
commit
2adbaf0899
@ -30,7 +30,8 @@ class QgsServerRequest
|
||||
%End
|
||||
public:
|
||||
|
||||
enum Method {
|
||||
enum Method
|
||||
{
|
||||
HeadMethod, PutMethod, GetMethod, PostMethod, DeleteMethod
|
||||
};
|
||||
|
||||
@ -61,12 +62,17 @@ class QgsServerRequest
|
||||
/**
|
||||
* @return the request url
|
||||
*/
|
||||
virtual QUrl url() const;
|
||||
QUrl url() const;
|
||||
|
||||
/**
|
||||
* @return the request method
|
||||
*/
|
||||
virtual Method method() const;
|
||||
Method method() const;
|
||||
|
||||
/**
|
||||
* * @return query params
|
||||
* */
|
||||
QMap<QString, QString> parameters() const;
|
||||
|
||||
/**
|
||||
* Return post/put data
|
||||
|
@ -18,7 +18,7 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "qgsserverrequest.h"
|
||||
|
||||
#include <QUrlQuery>
|
||||
|
||||
QgsServerRequest::QgsServerRequest( const QString& url, Method method )
|
||||
: mUrl( url )
|
||||
@ -56,6 +56,23 @@ QgsServerRequest::Method QgsServerRequest::method() const
|
||||
return mMethod;
|
||||
}
|
||||
|
||||
QMap<QString, QString> QgsServerRequest::parameters() const
|
||||
{
|
||||
// Lazy build of the parameter map
|
||||
if ( mParams.isEmpty() && mUrl.hasQuery() )
|
||||
{
|
||||
typedef QPair<QString, QString> pair_t;
|
||||
|
||||
QUrlQuery query( mUrl );
|
||||
QList<pair_t> items = query.queryItems();
|
||||
Q_FOREACH ( const pair_t& pair, items )
|
||||
{
|
||||
mParams.insert( pair.first.toUpper(), pair.second );
|
||||
}
|
||||
}
|
||||
return mParams;
|
||||
}
|
||||
|
||||
QByteArray QgsServerRequest::data() const
|
||||
{
|
||||
return QByteArray();
|
||||
|
@ -20,6 +20,7 @@
|
||||
#define QGSSERVERREQUEST_H
|
||||
|
||||
#include <QUrl>
|
||||
#include <QMap>
|
||||
|
||||
/**
|
||||
* \ingroup server
|
||||
@ -58,20 +59,21 @@ class SERVER_EXPORT QgsServerRequest
|
||||
//! destructor
|
||||
virtual ~QgsServerRequest();
|
||||
|
||||
/**
|
||||
* @return the value of the header field for that request
|
||||
*/
|
||||
virtual QString getHeader( const QString& name ) const;
|
||||
|
||||
/**
|
||||
* @return the request url
|
||||
*/
|
||||
virtual QUrl url() const;
|
||||
QUrl url() const;
|
||||
|
||||
/**
|
||||
* @return the request method
|
||||
*/
|
||||
virtual Method method() const;
|
||||
Method method() const;
|
||||
|
||||
/**
|
||||
* Return a map of query parameters with keys converted
|
||||
* to uppercase
|
||||
*/
|
||||
QMap<QString, QString> parameters() const;
|
||||
|
||||
/**
|
||||
* Return post/put data
|
||||
@ -80,10 +82,19 @@ class SERVER_EXPORT QgsServerRequest
|
||||
*/
|
||||
virtual QByteArray data() const;
|
||||
|
||||
protected:
|
||||
QUrl mUrl;
|
||||
Method mMethod;
|
||||
/**
|
||||
* @return the value of the header field for that request
|
||||
*/
|
||||
virtual QString getHeader( const QString& name ) const;
|
||||
|
||||
private:
|
||||
QUrl mUrl;
|
||||
Method mMethod;
|
||||
// We mark as mutable in order
|
||||
// to support lazy initialization
|
||||
// Use QMap here because it will be faster for small
|
||||
// number of elements
|
||||
mutable QMap<QString, QString> mParams;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -98,6 +98,8 @@ class SERVER_EXPORT QgsServiceRegistry
|
||||
void cleanUp();
|
||||
|
||||
private:
|
||||
// XXX consider using QMap because of the few numbers of
|
||||
// elements to handle
|
||||
typedef QHash<QString, std::shared_ptr<QgsService> > ServiceTable;
|
||||
typedef QHash<QString, QPair<QString, QString> > VersionTable;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user