Skip to content

Commit

Permalink
Remove the HTTPException
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Nov 28, 2023
1 parent c4e7aad commit 054bdcd
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions starlette/middleware/limits.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Middleware that limits the body size of incoming requests."""
from starlette.datastructures import Headers
from starlette.exceptions import HTTPException
from starlette.responses import PlainTextResponse
from starlette.types import ASGIApp, Message, Receive, Scope, Send

Expand All @@ -10,10 +9,9 @@
_content_too_large_app = PlainTextResponse("Content Too Large", status_code=413)


class ContentTooLarge(HTTPException):
class ContentTooLarge(Exception):
def __init__(self, max_body_size: int) -> None:
self.max_body_size = max_body_size
super().__init__(detail="Content Too Large", status_code=413)


class LimitBodySizeMiddleware:
Expand Down Expand Up @@ -63,6 +61,5 @@ async def wrap_receive() -> Message:
# NOTE: If response has already started, we can't return a 413, because the
# headers have already been sent.
if not response_started:
if "app" not in scope:
return await _content_too_large_app(scope, receive, send)
return await _content_too_large_app(scope, receive, send)
raise exc

0 comments on commit 054bdcd

Please sign in to comment.