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
Closes-Bug: #1213106
Co-Authored-By: Jamie Lennox <jamielennox@redhat.com>
This commit is contained in:
Brant Knudson 2015-01-01 18:49:04 -06:00
parent b25e8c5648
commit 7c8e3e1061
2 changed files with 14 additions and 1 deletions

View File

@ -66,7 +66,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:
msg = _("Request is too large.")

View File

@ -41,6 +41,14 @@ class TestLimitingReader(test_base.BaseTestCase):
self.assertEqual(bytes_read, BYTES)
def test_read_default_value(self):
BYTES = 1024
data_str = "*" * BYTES
data = six.StringIO(data_str)
reader = sizelimit.LimitingReader(data, BYTES)
res = reader.read()
self.assertEqual(data_str, res)
def test_limiting_reader_fails(self):
BYTES = 1024