Skip to content
Permalink
Browse files

[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
  • Loading branch information
backporting authored and rldhont committed Apr 11, 2019
1 parent fdb82fc commit e445a25c15c258d97a90ae7bfa754351f3e90e82
@@ -74,7 +74,7 @@ namespace QgsWcs
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

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

@@ -78,7 +78,7 @@ namespace QgsWfs
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

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

@@ -91,7 +91,7 @@ namespace QgsWms
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

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

@@ -72,7 +72,7 @@ namespace QgsWmts
if ( req.isEmpty() )
{
throw QgsServiceException( QStringLiteral( "OperationNotSupported" ),
QStringLiteral( "Please check the value of the REQUEST parameter" ) );
QStringLiteral( "Please check the value of the REQUEST parameter" ), 501 );
}

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

@@ -262,6 +262,12 @@ def _execute_request_project(self, qs, project, requestMethod=QgsServerRequest.G
headers.append(("%s: %s" % (k, rh[k])).encode('utf-8'))
return b"\n".join(headers) + b"\n\n", bytes(response.body())

def _assert_status_code(self, status_code, qs, requestMethod=QgsServerRequest.GetMethod, data=None, project=None):
request = QgsBufferServerRequest(qs, requestMethod, {}, data)
response = QgsBufferServerResponse()
self.server.handleRequest(request, response, project)
assert response.statusCode() == status_code, "%s != %s" % (response.statusCode(), status_code)


class TestQgsServerTestBase(unittest.TestCase):

@@ -92,6 +92,10 @@ def wfs_request_compare(self,
query_string, request))
return header, body

def test_operation_not_supported(self):
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.1.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
self._assert_status_code(501, qs)

def test_project_wfs(self):
"""Test some WFS request"""
for request in ('GetCapabilities', 'DescribeFeatureType'):
@@ -88,6 +88,10 @@ def test_getprojectsettings(self):
def test_getcontext(self):
self.wms_request_compare('GetContext')

def test_operation_not_supported(self):
qs = '?MAP=%s&SERVICE=WMS&VERSION=1.3.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
self._assert_status_code(501, qs)

def test_describelayer(self):
# Test DescribeLayer
self.wms_request_compare('DescribeLayer',
@@ -78,6 +78,10 @@ def wmts_request_compare(self, request, version='', extra_query_string='', refer

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

def test_operation_not_supported(self):
qs = '?MAP=%s&SERVICE=WFS&VERSION=1.0.0&REQUEST=NotAValidRequest' % urllib.parse.quote(self.projectPath)
self._assert_status_code(501, qs)

def test_project_wmts(self):
"""Test some WMTS request"""
for request in ('GetCapabilities',):

0 comments on commit e445a25

Please sign in to comment.
You can’t perform that action at this time.