Skip to content

Commit 2cda2af

Browse files
committedApr 5, 2019
Add test and sip
add missing methods Signed-off-by: Marco Bernasocchi <marco@opengis.ch> Update src/server/qgsserversettings.cpp Co-Authored-By: mbernasocchi <marco@opengis.ch> Update src/server/qgsserversettings.cpp Co-Authored-By: mbernasocchi <marco@opengis.ch> Update tests/src/python/test_qgsserver_wms_getmap.py Co-Authored-By: mbernasocchi <marco@opengis.ch> Update src/server/qgsserversettings.h Co-Authored-By: mbernasocchi <marco@opengis.ch> Adress most review comments in PR Signed-off-by: Marco Bernasocchi <marco@opengis.ch>
1 parent a938507 commit 2cda2af

File tree

6 files changed

+70
-15
lines changed

6 files changed

+70
-15
lines changed
 

‎python/server/auto_generated/qgsserversettings.sip.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ Show group (thousand) separator
134134

135135
:return: if group separator must be shown, default to ``False``.
136136

137+
.. versionadded:: 3.8
138+
%End
139+
140+
int wmsMaxHeight() const;
141+
%Docstring
142+
Returns the server-wide max height of a WMS GetMap request. The lower one of this and the project configuration is used.
143+
144+
:return: the max height of a WMS GetMap request.
145+
146+
.. versionadded:: 3.8
147+
%End
148+
149+
int wmsMaxWidth() const;
150+
%Docstring
151+
Returns the server-wide max width of a WMS GetMap request. The lower one of this and the project configuration is used.
152+
153+
:return: the max width of a WMS GetMap request.
154+
137155
.. versionadded:: 3.8
138156
%End
139157

‎src/server/qgsserversettings.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void QgsServerSettings::initSettings()
165165
// max height
166166
const Setting sMaxHeight = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT,
167167
QgsServerSettingsEnv::DEFAULT_VALUE,
168-
"Maximum height for a WMS request. The most conservative between this and the project one is used",
168+
"Maximum height for a WMS request. The lower one of this and the project configuration is used.",
169169
"/qgis/max_wms_height",
170170
QVariant::LongLong,
171171
QVariant( -1 ),
@@ -363,3 +363,23 @@ QString QgsServerSettings::cacheDirectory() const
363363
{
364364
return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
365365
}
366+
367+
QString QgsServerSettings::overrideSystemLocale() const
368+
{
369+
return value( QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE ).toString();
370+
}
371+
372+
bool QgsServerSettings::showGroupSeparator() const
373+
{
374+
return value( QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR ).toBool();
375+
}
376+
377+
int QgsServerSettings::wmsMaxHeight() const
378+
{
379+
return value( QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT ).toInt();
380+
}
381+
382+
int QgsServerSettings::wmsMaxWidth() const
383+
{
384+
return value( QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH ).toInt();
385+
}

‎src/server/qgsserversettings.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,16 @@ class SERVER_EXPORT QgsServerSettings
185185
* \since QGIS 3.8
186186
*/
187187
bool showGroupSeparator() const;
188-
188+
189189
/**
190-
* Returns the max height of a WMS GetMap request.
191-
* \returns Returns the max height of a WMS GetMap request.
190+
* Returns the server-wide max height of a WMS GetMap request. The lower one of this and the project configuration is used.
191+
* \returns the max height of a WMS GetMap request.
192192
* \since QGIS 3.8
193193
*/
194194
int wmsMaxHeight() const;
195195

196196
/**
197-
* Returns the max width of a WMS GetMap request.
197+
* Returns the server-wide max width of a WMS GetMap request. The lower one of this and the project configuration is used.
198198
* \returns the max width of a WMS GetMap request.
199199
* \since QGIS 3.8
200200
*/

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,17 +1875,17 @@ namespace QgsWms
18751875
//and WIDTH / HEIGHT parameter is in the range allowed range
18761876
//WIDTH
18771877
int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
1878-
int wmsMaxWidthEnv = mServerSettings.wmsMaxWidth();
1878+
int wmsMaxWidthEnv = mContext.settings().wmsMaxWidth();
18791879
int wmsMaxWidth;
18801880
if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
18811881
{
18821882
// both are set, so we take the more conservative one
1883-
wmsMaxWidth = qMin( wmsMaxWidthProj, wmsMaxWidthEnv );
1883+
wmsMaxWidth = std::min( wmsMaxWidthProj, wmsMaxWidthEnv );
18841884
}
18851885
else
18861886
{
18871887
// none or one are set, so we take the bigger one which is the one set or -1
1888-
wmsMaxWidth = qMax( wmsMaxWidthProj, wmsMaxWidthEnv );
1888+
wmsMaxWidth = std::max( wmsMaxWidthProj, wmsMaxWidthEnv );
18891889
}
18901890

18911891
int width = this->width();
@@ -1896,17 +1896,17 @@ namespace QgsWms
18961896

18971897
//HEIGHT
18981898
int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
1899-
int wmsMaxHeightEnv = mServerSettings.wmsMaxHeight();
1899+
int wmsMaxHeightEnv = mContext.settings().wmsMaxHeight();
19001900
int wmsMaxHeight;
19011901
if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
19021902
{
19031903
// both are set, so we take the more conservative one
1904-
wmsMaxHeight = qMin( wmsMaxHeightProj, wmsMaxHeightEnv );
1904+
wmsMaxHeight = std::min( wmsMaxHeightProj, wmsMaxHeightEnv );
19051905
}
19061906
else
19071907
{
19081908
// none or one are set, so we take the bigger one which is the one set or -1
1909-
wmsMaxHeight = qMax( wmsMaxHeightProj, wmsMaxHeightEnv );
1909+
wmsMaxHeight = std::max( wmsMaxHeightProj, wmsMaxHeightEnv );
19101910
}
19111911

19121912
int height = this->height();

‎src/server/services/wms/qgswmsrenderer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ namespace QgsWms
283283

284284
QgsWmsParameters mWmsParameters;
285285

286-
QgsServerSettings mServerSettings;
287-
288286
QgsFeatureFilter mFeatureFilter;
289287

290288
const QgsProject *mProject = nullptr;

‎tests/src/python/test_qgsserver_wms_getmap.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ def test_wms_getmap_background(self):
617617

618618
def test_wms_getmap_invalid_size(self):
619619
project = os.path.join(self.testdata_path, "test_project_with_size.qgs")
620+
expected = self.strip_version_xmlns(b'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="InvalidParameterValue">The requested map size is too large</ServiceException>\n</ServiceExceptionReport>\n')
621+
622+
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = 6000
623+
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = 6000
624+
# test the 6000 limit from server is overriden by the more conservative 5000 in the project
620625
qs = "?" + "&".join(["%s=%s" % i for i in list({
621626
"MAP": urllib.parse.quote(project),
622627
"SERVICE": "WMS",
@@ -628,10 +633,24 @@ def test_wms_getmap_invalid_size(self):
628633
"HEIGHT": "5001",
629634
"WIDTH": "5000"
630635
}.items())])
631-
632-
expected = self.strip_version_xmlns(b'<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">\n <ServiceException code="InvalidParameterValue">The requested map size is too large</ServiceException>\n</ServiceExceptionReport>\n')
633636
r, h = self._result(self._execute_request(qs))
637+
self.assertEqual(self.strip_version_xmlns(r), expected)
634638

639+
# test the QGIS_SERVER_WMS_MAX_XXX env vars
640+
os.environ['QGIS_SERVER_WMS_MAX_WIDTH'] = 3000
641+
os.environ['QGIS_SERVER_WMS_MAX_HEIGHT'] = 3000
642+
qs = "?" + "&".join(["%s=%s" % i for i in list({
643+
"MAP": urllib.parse.quote(project),
644+
"SERVICE": "WMS",
645+
"VERSION": "1.3.0",
646+
"REQUEST": "GetMap",
647+
"LAYERS": "",
648+
"STYLES": "",
649+
"FORMAT": "image/png",
650+
"HEIGHT": "3000",
651+
"WIDTH": "3001"
652+
}.items())])
653+
r, h = self._result(self._execute_request(qs))
635654
self.assertEqual(self.strip_version_xmlns(r), expected)
636655

637656
def test_wms_getmap_order(self):

0 commit comments

Comments
 (0)
Please sign in to comment.