Skip to content

Commit 09b8a57

Browse files
authoredApr 11, 2019
Merge pull request #9769 from dmarteau/Fix-OperationNotSupported-http-code
Return 501 on 'OperationNotSupported' error
2 parents 6792d23 + 69728d4 commit 09b8a57

File tree

8 files changed

+28
-10
lines changed

8 files changed

+28
-10
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ namespace QgsWms
9090
const QString req = parameters.request();
9191
if ( req.isEmpty() )
9292
{
93-
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
94-
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
93+
throw QgsServiceException( QgsServiceException::OGC_OPERATION_NOT_SUPPORTED,
94+
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
9595
}
9696

9797
if ( ( mVersion.compare( QLatin1String( "1.1.1" ) ) == 0 \
@@ -153,8 +153,8 @@ namespace QgsWms
153153
else
154154
{
155155
// Operation not supported
156-
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
157-
QString( "Request %1 is not supported" ).arg( req ) );
156+
throw QgsServiceException( QgsServiceException::OGC_OPERATION_NOT_SUPPORTED,
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
@@ -259,6 +259,12 @@ def _execute_request_project(self, qs, project, requestMethod=QgsServerRequest.G
259259
headers.append(("%s: %s" % (k, rh[k])).encode('utf-8'))
260260
return b"\n".join(headers) + b"\n\n", bytes(response.body())
261261

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

263269
class TestQgsServerTestBase(unittest.TestCase):
264270

‎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
@@ -107,6 +107,10 @@ def wmts_request_compare_project(self, project, request, version='', extra_query
107107

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

110+
def test_operation_not_supported(self):
111+
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.0.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
112+
self._assert_status_code(501, qs)
113+
110114
def test_project_wmts(self):
111115
"""Test some WMTS request"""
112116
for request in ('GetCapabilities',):

0 commit comments

Comments
 (0)
Please sign in to comment.