From e73f26b0a326d42ea9dc5472e6cb237facc7c852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Mon, 2 Mar 2020 15:32:12 +0200 Subject: [PATCH] More specific error messages on Payload Too Large. --- sanic/http.py | 4 ++-- tests/test_payload_too_large.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sanic/http.py b/sanic/http.py index 20a3066b..3c79d6c1 100644 --- a/sanic/http.py +++ b/sanic/http.py @@ -116,7 +116,7 @@ class Http: break await self._receive_more() if pos >= self.request_max_size: - raise PayloadTooLarge("Payload Too Large") + raise PayloadTooLarge("Request header too large") # Parse header content try: reqline, *raw_headers = buf[:pos].decode().split("\r\n") @@ -347,7 +347,7 @@ class Http: # Request size limit if self.request_bytes > self.request_max_size: self.keep_alive = False - raise PayloadTooLarge("Payload Too Large") + raise PayloadTooLarge("Request body too large") # End of request body? if not self.request_bytes_left: self.request_body = None diff --git a/tests/test_payload_too_large.py b/tests/test_payload_too_large.py index 7b2e6aaa..45d46444 100644 --- a/tests/test_payload_too_large.py +++ b/tests/test_payload_too_large.py @@ -27,7 +27,7 @@ def test_payload_too_large_at_data_received_default(app): response = app.test_client.get("/1", gather_request=False) assert response.status == 413 - assert "Payload Too Large" in response.text + assert "Request header" in response.text def test_payload_too_large_at_on_header_default(app): @@ -40,4 +40,4 @@ def test_payload_too_large_at_on_header_default(app): data = "a" * 1000 response = app.test_client.post("/1", gather_request=False, data=data) assert response.status == 413 - assert "Payload Too Large" in response.text + assert "Request body" in response.text