sanic/app: When streaming, check REQUEST_MAX_SIZE if length is known
This commit is contained in:
parent
af67801062
commit
2f8628eed3
|
@ -57,6 +57,7 @@ from sanic.compat import OS_IS_WINDOWS, enable_windows_color_support
|
||||||
from sanic.config import SANIC_PREFIX, Config
|
from sanic.config import SANIC_PREFIX, Config
|
||||||
from sanic.exceptions import (
|
from sanic.exceptions import (
|
||||||
BadRequest,
|
BadRequest,
|
||||||
|
PayloadTooLarge,
|
||||||
SanicException,
|
SanicException,
|
||||||
ServerError,
|
ServerError,
|
||||||
URLBuildError,
|
URLBuildError,
|
||||||
|
@ -933,9 +934,11 @@ class Sanic(StaticHandleMixin, BaseSanic, StartupMixin, metaclass=TouchUpMeta):
|
||||||
and request.stream.request_body
|
and request.stream.request_body
|
||||||
and not route.extra.ignore_body
|
and not route.extra.ignore_body
|
||||||
):
|
):
|
||||||
|
|
||||||
if hasattr(handler, "is_stream"):
|
if hasattr(handler, "is_stream"):
|
||||||
# Streaming handler: lift the size limit
|
rq_len = request.stream.request_bytes
|
||||||
request.stream.request_max_size = float("inf")
|
if rq_len and rq_len > request.stream.request_max_size:
|
||||||
|
raise PayloadTooLarge("Request body exceeds the size limit")
|
||||||
else:
|
else:
|
||||||
# Non-streaming handler: preload body
|
# Non-streaming handler: preload body
|
||||||
await request.receive_body()
|
await request.receive_body()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user