Skip to content

Commit

Permalink
Merge pull request #2963 from elpaso/server-fix-qs-encoding
Browse files Browse the repository at this point in the history
[SERVER] Fix encoding of query string for bindings
  • Loading branch information
elpaso committed Apr 4, 2016
2 parents 5414637 + 5a72bc7 commit ff17645
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/server/qgsserver.cpp
Expand Up @@ -441,9 +441,9 @@ bool QgsServer::init( int & argc, char ** argv )
void QgsServer::putenv( const QString &var, const QString &val )
{
#ifdef _MSC_VER
_putenv_s( var.toUtf8().data(), val.toUtf8().data() );
_putenv_s( var.toStdString().c_str(), val.toStdString().c_str() );
#else
setenv( var.toUtf8().data(), val.toUtf8().data(), 1 );
setenv( var.toStdString().c_str(), val.toStdString().c_str(), 1 );
#endif
}

Expand Down
32 changes: 24 additions & 8 deletions tests/src/python/test_qgsserver.py
Expand Up @@ -41,6 +41,13 @@ def setUp(self):
pass
self.server = QgsServer()

def assert_headers(self, header, body):
headers = Message(StringIO(header))
if 'content-length' in headers:
content_length = int(headers['content-length'])
body_length = len(body)
self.assertEqual(content_length, body_length, msg="Header reported content-length: %d Actual body length was: %d" % (content_length, body_length))

def test_destructor_segfaults(self):
"""Segfault on destructor?"""
server = QgsServer()
Expand Down Expand Up @@ -294,20 +301,29 @@ def test_getfeature(self):
for id, req in tests:
self.wfs_getfeature_compare(id, req)

def assert_headers(self, header, body):
headers = Message(StringIO(header))
if 'content-length' in headers:
content_length = int(headers['content-length'])
body_length = len(body)
self.assertEqual(content_length, body_length, msg="Header reported content-length: %d Actual body length was: %d" % (content_length, body_length))
def test_getLegendGraphics(self):
"""Test that does not return an exception but an image"""
parms = {
'MAP': self.testdata_path + "test%2Bproject.qgs",
'SERVICE': 'WMS',
'VERSIONE': '1.0.0',
'REQUEST': 'GetLegendGraphic',
'FORMAT': 'image/png',
#'WIDTH': '20', # optional
#'HEIGHT': '20', # optional
'LAYER': u'testlayer+èé',
}
qs = '&'.join([u"%s=%s" % (k, v) for k, v in parms.iteritems()])
h, r = self.server.handleRequest(qs)
self.assertEquals(-1, h.find('Content-Type: text/xml; charset=utf-8'), "Header: %s\nResponse:\n%s" % (h, r))
self.assertNotEquals(-1, h.find('Content-Type: image/png'), "Header: %s\nResponse:\n%s" % (h, r))


# The following code was used to test type conversion in python bindings
# def test_qpair(self):
# """Test QPair bindings"""
# f, s = self.server.testQPair(('First', 'Second'))
# self.assertEqual(f, 'First')
# self.assertEqual(s, 'Second')


if __name__ == '__main__':
unittest.main()

0 comments on commit ff17645

Please sign in to comment.