From bdd548e4be87167ea41cdd2184ba577c56661ec4 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 12 Jul 2021 10:21:06 +0300 Subject: [PATCH 1/4] Change dumps to AnyStr --- sanic/app.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index ec9027b512..fc037396d2 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -21,6 +21,7 @@ from types import SimpleNamespace from typing import ( Any, + AnyStr, Awaitable, Callable, Coroutine, @@ -137,7 +138,7 @@ def __init__( log_config: Optional[Dict[str, Any]] = None, configure_logging: bool = True, register: Optional[bool] = None, - dumps: Optional[Callable[..., str]] = None, + dumps: Optional[Callable[..., AnyStr]] = None, ) -> None: super().__init__(name=name) @@ -736,9 +737,7 @@ async def handle_request(self, request: Request): if hasattr(handler, "is_stream"): # Streaming handler: lift the size limit - request.stream.request_max_size = float( # type: ignore - "inf" - ) + request.stream.request_max_size = float("inf") # type: ignore else: # Non-streaming handler: preload body await request.receive_body() From 41becb3d52c610b6f4df7e507474b4162314dc1b Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 19 Jul 2021 09:27:27 +0300 Subject: [PATCH 2/4] squash --- sanic/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/app.py b/sanic/app.py index fc037396d2..9f186c6e01 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -193,7 +193,7 @@ def __init__( self.router.ctx.app = self if dumps: - BaseHTTPResponse._dumps = dumps + BaseHTTPResponse._dumps = dumps # type: ignore @property def loop(self): From 268cf3ad0519d3b8fbcdb2db27e730b06309ee44 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 19 Jul 2021 09:42:28 +0300 Subject: [PATCH 3/4] squash --- sanic/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 1e60067bcc..20a1668115 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -742,9 +742,9 @@ async def handle_request(self, request: Request): and not route.ctx.ignore_body ): - if hasattr(handler, "is_stream"): + if hasattr(handler, "is_stream") and request.stream: # Streaming handler: lift the size limit - request.stream.request_max_size = float("inf") # type: ignore + request.stream.request_max_size = float("inf") else: # Non-streaming handler: preload body await request.receive_body() From 7870235cfc2fd32a8767f4c17765367d77773701 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 19 Jul 2021 09:43:10 +0300 Subject: [PATCH 4/4] squash --- sanic/app.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index 20a1668115..ac346d7381 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -738,11 +738,12 @@ async def handle_request(self, request: Request): request.route = route if ( - request.stream.request_body # type: ignore + request.stream + and request.stream.request_body and not route.ctx.ignore_body ): - if hasattr(handler, "is_stream") and request.stream: + if hasattr(handler, "is_stream"): # Streaming handler: lift the size limit request.stream.request_max_size = float("inf") else: