Skip to content

Commit e445a25

Browse files
backporting[bot]rldhont
authored andcommittedApr 11, 2019
[Backport release-3_4] Return 501 on 'OperationNotSupported' error (#9770)
Return 501 HTTP statues code 'OperationNotSupported' Error According to OGC/OWS standard, 'OperationNotSupported' Error should return 501 but actually return 200. ref http://docs.opengeospatial.org/is/17-007r1/17-007r1.html - table 21
1 parent fdb82fc commit e445a25

File tree

8 files changed

+26
-8
lines changed

8 files changed

+26
-8
lines changed
 

‎src/server/services/wcs/qgswcs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace QgsWcs
7474
if ( req.isEmpty() )
7575
{
7676
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
77-
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
77+
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
7878
}
7979

8080
if ( QSTR_COMPARE( req, "GetCapabilities" ) )
@@ -93,7 +93,7 @@ namespace QgsWcs
9393
{
9494
// Operation not supported
9595
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
96-
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
96+
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
9797
}
9898
}
9999

‎src/server/services/wfs/qgswfs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace QgsWfs
7878
if ( req.isEmpty() )
7979
{
8080
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
81-
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
81+
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
8282
}
8383

8484
if ( QSTR_COMPARE( req, "GetCapabilities" ) )
@@ -117,7 +117,7 @@ namespace QgsWfs
117117
{
118118
// Operation not supported
119119
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
120-
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
120+
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
121121
}
122122
}
123123

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace QgsWms
9191
if ( req.isEmpty() )
9292
{
9393
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
94-
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
94+
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
9595
}
9696

9797
if ( ( mVersion.compare( QLatin1String( "1.1.1" ) ) == 0 \
@@ -154,7 +154,7 @@ namespace QgsWms
154154
{
155155
// Operation not supported
156156
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
157-
QString( "Request %1 is not supported" ).arg( req ) );
157+
QString( "Request %1 is not supported" ).arg( req ), 501 );
158158
}
159159
}
160160

‎src/server/services/wmts/qgswmts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace QgsWmts
7272
if ( req.isEmpty() )
7373
{
7474
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
75-
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
75+
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
7676
}
7777

7878
if ( QSTR_COMPARE( req, "GetCapabilities" ) )
@@ -91,7 +91,7 @@ namespace QgsWmts
9191
{
9292
// Operation not supported
9393
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
94-
QStringLiteral( "Request %1 is not supported" ).arg( req ) );
94+
QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
9595
}
9696
}
9797

‎tests/src/python/test_qgsserver.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ def _execute_request_project(self, qs, project, requestMethod=QgsServerRequest.G
262262
headers.append(("%s: %s" % (k, rh[k])).encode('utf-8'))
263263
return b"\n".join(headers) + b"\n\n", bytes(response.body())
264264

265+
def _assert_status_code(self, status_code, qs, requestMethod=QgsServerRequest.GetMethod, data=None, project=None):
266+
request = QgsBufferServerRequest(qs, requestMethod, {}, data)
267+
response = QgsBufferServerResponse()
268+
self.server.handleRequest(request, response, project)
269+
assert response.statusCode() == status_code, "%s != %s" % (response.statusCode(), status_code)
270+
265271

266272
class TestQgsServerTestBase(unittest.TestCase):
267273

‎tests/src/python/test_qgsserver_wfs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def wfs_request_compare(self,
9292
query_string, request))
9393
return header, body
9494

95+
def test_operation_not_supported(self):
96+
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.1.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
97+
self._assert_status_code(501, qs)
98+
9599
def test_project_wfs(self):
96100
"""Test some WFS request"""
97101
for request in ('GetCapabilities', 'DescribeFeatureType'):

‎tests/src/python/test_qgsserver_wms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def test_getprojectsettings(self):
8888
def test_getcontext(self):
8989
self.wms_request_compare('GetContext')
9090

91+
def test_operation_not_supported(self):
92+
qs = '?MAP=%s&SERVICE=WMS&VERSION=1.3.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
93+
self._assert_status_code(501, qs)
94+
9195
def test_describelayer(self):
9296
# Test DescribeLayer
9397
self.wms_request_compare('DescribeLayer',

‎tests/src/python/test_qgsserver_wmts.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ def wmts_request_compare(self, request, version='', extra_query_string='', refer
7878

7979
self.assertXMLEqual(response, expected, msg="request %s failed.\n Query: %s" % (query_string, request))
8080

81+
def test_operation_not_supported(self):
82+
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.0.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
83+
self._assert_status_code(501, qs)
84+
8185
def test_project_wmts(self):
8286
"""Test some WMTS request"""
8387
for request in ('GetCapabilities',):

0 commit comments

Comments
 (0)
Please sign in to comment.