Don't use default value in LimitingReader

We can't simply pass the None default on to the read operation as this
default is handled differently between different wsgi implementations.

Change-Id: I337e797b8dee3dfcf9299fe361cf197a176c8fe2
Fixes: bug 1213106
This commit is contained in:
Jamie Lennox 2013-10-09 11:49:58 +10:00 committed by Dolph Mathews
parent e93365554f
commit c14ebd668f
2 changed files with 29 additions and 1 deletions

View File

@ -290,7 +290,12 @@ class LimitingReader(object):
yield chunk
def read(self, i=None):
result = self.data.read(i)
# NOTE(jamielennox): We can't simply provide the default to the read()
# call as the expected default differs between mod_wsgi and eventlet
if i is None:
result = self.data.read()
else:
result = self.data.read(i)
self.bytes_read += len(result)
if self.bytes_read > self.limit:
raise exception.RequestTooLarge()

View File

@ -105,3 +105,26 @@ class UtilsTestCase(tests.TestCase):
for d in ['+0', '-11', '-8', '-5', '+5', '+8', '+14']:
TZ = 'UTC' + d
_test_unixtime()
class LimitingReaderTests(tests.TestCase):
def test_read_default_value(self):
class FakeData(object):
def read(self, *args, **kwargs):
self.read_args = args
self.read_kwargs = kwargs
return 'helloworld'
data = FakeData()
utils.LimitingReader(data, 100)
self.assertEqual(data.read(), 'helloworld')
self.assertEqual(len(data.read_args), 0)
self.assertEqual(len(data.read_kwargs), 0)
self.assertEqual(data.read(10), 'helloworld')
self.assertEqual(len(data.read_args), 1)
self.assertEqual(len(data.read_kwargs), 0)
self.assertEqual(data.read_args[0], 10)