Make sure we update remaining length, and update test to catch the edge case

this fixes.
This commit is contained in:
Itamar Turner-Trauring 2022-07-06 09:40:46 -04:00
parent 5c5556d915
commit dac0080ea2
2 changed files with 3 additions and 2 deletions

View File

@ -125,7 +125,8 @@ class _LengthLimitedCollector:
f: BytesIO = field(factory=BytesIO)
def __call__(self, data: bytes):
if len(data) > self.remaining_length:
self.remaining_length -= len(data)
if self.remaining_length < 0:
raise ValueError("Response length was too long")
self.f.write(data)

View File

@ -337,7 +337,7 @@ class CustomHTTPServerTests(SyncTestCase):
``http_client.limited_content()`` returns the body if it is less than
the max length.
"""
for at_least_length in (length, length + 1, length + 1000):
for at_least_length in (length, length + 1, length + 1000, length + 100_000):
response = result_of(
self.client.request(
"GET",