Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanic/app: When streaming, check REQUEST_MAX_SIZE if length is known #2745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions sanic/app.py
Expand Up @@ -57,6 +57,7 @@
from sanic.config import SANIC_PREFIX, Config
from sanic.exceptions import (
BadRequest,
PayloadTooLarge,
SanicException,
ServerError,
URLBuildError,
Expand Down Expand Up @@ -933,9 +934,11 @@ async def handle_request(self, request: Request): # no cov
and request.stream.request_body
and not route.extra.ignore_body
):

if hasattr(handler, "is_stream"):
# Streaming handler: lift the size limit
request.stream.request_max_size = float("inf")
rq_len = request.stream.request_bytes
if rq_len and rq_len > request.stream.request_max_size:
raise PayloadTooLarge("Request body exceeds the size limit")
else:
# Non-streaming handler: preload body
await request.receive_body()
Expand Down