Skip to content
Permalink
Browse files

Header enum

  • Loading branch information
sbrunner committed Mar 12, 2021
1 parent af01a41 commit b06cf95dba0c83bd43001495db8905511b1de5cb
@@ -1,2 +1,3 @@
# The following has been generated automatically from src/server/qgsserverrequest.h
QgsServerRequest.Method.baseClass = QgsServerRequest
QgsServerRequest.RequestHeader.baseClass = QgsServerRequest
@@ -34,15 +34,28 @@ class QgsServerRequest
PatchMethod
};

static const QString HOST;
static const QString FORWARDED;
static const QString X_FORWARDED_HOST;
static const QString X_FORWARDED_PROTO;
static const QString X_QGIS_SERVICE_URL;
static const QString X_QGIS_WMS_SERVICE_URL;
static const QString X_QGIS_WFS_SERVICE_URL;
static const QString X_QGIS_WCS_SERVICE_URL;
static const QString X_QGIS_WMTS_SERVICE_URL;
enum RequestHeader
{
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
HOST,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
// https://tools.ietf.org/html/rfc7239
FORWARDED,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
X_FORWARDED_HOST,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
X_FORWARDED_PROTO,
// The QGIS service URL
X_QGIS_SERVICE_URL,
// The QGIS WMS service URL
X_QGIS_WMS_SERVICE_URL,
// The QGIS WFS service URL
X_QGIS_WFS_SERVICE_URL,
// The QGIS WCS service URL
X_QGIS_WCS_SERVICE_URL,
// The QGIS WMTS service URL
X_QGIS_WMTS_SERVICE_URL,
};

QgsServerRequest();
%Docstring
@@ -130,6 +143,15 @@ Returns the header value

:param name: of the header

:return: the header value or an empty string
%End

virtual QString header( const RequestHeader &headerEnum ) const;
%Docstring
Returns the header value

:param headerEnum: of the header

:return: the header value or an empty string
%End

@@ -153,6 +175,8 @@ Returns the header map
Remove an header

:param name:

.. versionadded:: 3.20
%End

virtual QByteArray data() const;
@@ -324,29 +324,29 @@ QString QgsServerProjectUtils::serviceUrl( const QString &service, const QgsServ
return url;
}

QString header = QgsServerRequest::X_QGIS_SERVICE_URL;
QgsServerRequest::RequestHeader header = QgsServerRequest::RequestHeader::X_QGIS_SERVICE_URL;
if ( serviceUpper == QStringLiteral( "WMS" ) )
{
header = QgsServerRequest::X_QGIS_WMS_SERVICE_URL;
header = QgsServerRequest::RequestHeader::X_QGIS_WMS_SERVICE_URL;
}
else if ( serviceUpper == QStringLiteral( "WFS" ) )
{
header = QgsServerRequest::X_QGIS_WFS_SERVICE_URL;
header = QgsServerRequest::RequestHeader::X_QGIS_WFS_SERVICE_URL;
}
else if ( serviceUpper == QStringLiteral( "WCS" ) )
{
header = QgsServerRequest::X_QGIS_WCS_SERVICE_URL;
header = QgsServerRequest::RequestHeader::X_QGIS_WCS_SERVICE_URL;
}
else if ( serviceUpper == QStringLiteral( "WMTS" ) )
{
header = QgsServerRequest::X_QGIS_WMTS_SERVICE_URL;
header = QgsServerRequest::RequestHeader::X_QGIS_WMTS_SERVICE_URL;
}
url = request.header( header );
if ( ! url.isEmpty() )
{
return url;
}
url = request.header( QgsServerRequest::X_QGIS_SERVICE_URL );
url = request.header( QgsServerRequest::RequestHeader::X_QGIS_SERVICE_URL );
if ( ! url.isEmpty() )
{
return url;
@@ -376,13 +376,13 @@ QString QgsServerProjectUtils::serviceUrl( const QString &service, const QgsServ

if ( host.isEmpty() )
{
host = request.header( QgsServerRequest::X_FORWARDED_HOST );
proto = request.header( QgsServerRequest::X_FORWARDED_PROTO );
host = request.header( QgsServerRequest::RequestHeader::X_FORWARDED_HOST );
proto = request.header( QgsServerRequest::RequestHeader::X_FORWARDED_PROTO );
}

if ( host.isEmpty() )
{
host = request.header( QgsServerRequest::HOST );
host = request.header( QgsServerRequest::RequestHeader::HOST );
}

QUrl urlQUrl = request.baseUrl();
@@ -21,16 +21,6 @@
#include <QUrlQuery>


const QString QgsServerRequest::HOST = QStringLiteral( "Host" );
const QString QgsServerRequest::FORWARDED = QStringLiteral( "Forwarded" );
const QString QgsServerRequest::X_FORWARDED_HOST = QStringLiteral( "X-Forwarded-Host" );
const QString QgsServerRequest::X_FORWARDED_PROTO = QStringLiteral( "X-Forwarded-Proto" );
const QString QgsServerRequest::X_QGIS_SERVICE_URL = QStringLiteral( "X-Qgis-Service-Url" );
const QString QgsServerRequest::X_QGIS_WMS_SERVICE_URL = QStringLiteral( "X-Qgis-Wms-Service-Url" );
const QString QgsServerRequest::X_QGIS_WFS_SERVICE_URL = QStringLiteral( "X-Qgis-Wfs-Service-Url" );
const QString QgsServerRequest::X_QGIS_WCS_SERVICE_URL = QStringLiteral( "X-Qgis-Wcs-Service-Url" );
const QString QgsServerRequest::X_QGIS_WMTS_SERVICE_URL = QStringLiteral( "X-Qgis-Wmts-Service-Url" );

QgsServerRequest::QgsServerRequest( const QString &url, Method method, const Headers &headers )
: QgsServerRequest( QUrl( url ), method, headers )
{
@@ -42,7 +32,18 @@ QgsServerRequest::QgsServerRequest( const QUrl &url, Method method, const Header
, mBaseUrl( url )
, mMethod( method )
, mHeaders( headers )
{
, mRequestHeaderConv()
{
mRequestHeaderConv.add( HOST, "Host" )
mRequestHeaderConv.add( FORWARDED, "Forwarded" )
mRequestHeaderConv.add( X_FORWARDED_HOST, "X-Forwarded-Host" )
mRequestHeaderConv.add( X_FORWARDED_PROTO, "X-Forwarded-Proto" )
mRequestHeaderConv.add( X_QGIS_SERVICE_URL, "X-Qgis-Service-Url" )
mRequestHeaderConv.add( X_QGIS_WMS_SERVICE_URL, "X-Qgis-Wms-Service-Url" )
mRequestHeaderConv.add( X_QGIS_WFS_SERVICE_URL, "X-Qgis-Wfs-Service-Url" )
mRequestHeaderConv.add( X_QGIS_WCS_SERVICE_URL, "X-Qgis-Wcs-Service-Url" )
mRequestHeaderConv.add( X_QGIS_WMTS_SERVICE_URL, "X-Qgis-Wmts-Service-Url" )

mParams.load( QUrlQuery( url ) );
}

@@ -53,6 +54,7 @@ QgsServerRequest::QgsServerRequest( const QgsServerRequest &other )
, mMethod( other.mMethod )
, mHeaders( other.mHeaders )
, mParams( other.mParams )
, mRequestHeaderConv( other.mRequestHeaderConv )
{
}

@@ -67,6 +69,12 @@ QString QgsServerRequest::header( const QString &name ) const
return mHeaders.value( name );
}


QString header( const RequestHeader &headerEnum ) const;
{
return header( mRequestHeaderConv.get( headerEnum ) )
}

void QgsServerRequest::setHeader( const QString &name, const QString &value )
{
mHeaders.insert( name, value );
@@ -59,27 +59,31 @@ class SERVER_EXPORT QgsServerRequest
Q_ENUM( Method )

/**
* HTTP Headers used for the request
* The internal HTTP Header used for the request as enum
*/
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
static const QString HOST;
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
// https://tools.ietf.org/html/rfc7239
static const QString FORWARDED;
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
static const QString X_FORWARDED_HOST;
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
static const QString X_FORWARDED_PROTO;
// The QGIS service URL
static const QString X_QGIS_SERVICE_URL;
// The QGIS WMS service URL
static const QString X_QGIS_WMS_SERVICE_URL;
// The QGIS WFS service URL
static const QString X_QGIS_WFS_SERVICE_URL;
// The QGIS WCS service URL
static const QString X_QGIS_WCS_SERVICE_URL;
// The QGIS WMTS service URL
static const QString X_QGIS_WMTS_SERVICE_URL;
enum RequestHeader
{
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host
HOST,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
// https://tools.ietf.org/html/rfc7239
FORWARDED,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
X_FORWARDED_HOST,
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
X_FORWARDED_PROTO,
// The QGIS service URL
X_QGIS_SERVICE_URL,
// The QGIS WMS service URL
X_QGIS_WMS_SERVICE_URL,
// The QGIS WFS service URL
X_QGIS_WFS_SERVICE_URL,
// The QGIS WCS service URL
X_QGIS_WCS_SERVICE_URL,
// The QGIS WMTS service URL
X_QGIS_WMTS_SERVICE_URL,
};
Q_ENUM( RequestHeader )

/**
* Constructor
@@ -167,6 +171,13 @@ class SERVER_EXPORT QgsServerRequest
*/
virtual QString header( const QString &name ) const;

/**
* Returns the header value
* \param headerEnum of the header
* \return the header value or an empty string
*/
virtual QString header( const RequestHeader &headerEnum ) const;

/**
* Set an header
* \param name
@@ -181,9 +192,10 @@ class SERVER_EXPORT QgsServerRequest
QMap<QString, QString> headers() const;

/**
* Remove an header
* \param name
*/
* Remove an header
* \param name
* \since QGIS 3.20
*/
void removeHeader( const QString &name );

/**
@@ -259,6 +271,7 @@ class SERVER_EXPORT QgsServerRequest
// to support lazy initialization
mutable Headers mHeaders;
QgsServerParameters mParams;
QMap<RequestHeader, QString> mRequestHeaderConv;
};

#endif

0 comments on commit b06cf95

Please sign in to comment.