Limit the size of the request body

This commit is contained in:
Miguel Grinberg
2021-09-27 17:01:43 +01:00
parent 4ed101dfc6
commit 5003a5b3d9
6 changed files with 187 additions and 68 deletions

View File

@@ -88,3 +88,15 @@ class TestRequestAsync(unittest.TestCase):
body='foo=bar&abc=def&x=%2f%%')
req = _run(Request.create('app', fd, 'addr'))
self.assertIsNone(req.form)
def test_large_payload(self):
saved_max_content_length = Request.max_content_length
Request.max_content_length = 16
fd = get_async_request_fd('GET', '/foo', headers={
'Content-Type': 'application/x-www-form-urlencoded'},
body='foo=bar&abc=def&x=y')
req = _run(Request.create('app', fd, 'addr'))
assert req.body == b''
Request.max_content_length = saved_max_content_length