Skip to content

fix(multipart): return HTTP 413 for size limit violations#4484

Closed
nclimaz wants to merge 6 commits intolitestar-org:mainfrom
nclimaz:fix/multipart-413-error
Closed

fix(multipart): return HTTP 413 for size limit violations#4484
nclimaz wants to merge 6 commits intolitestar-org:mainfrom
nclimaz:fix/multipart-413-error

Conversation

@nclimaz
Copy link
Copy Markdown

@nclimaz nclimaz commented Nov 20, 2025

Changed ClientException to RequestEntityTooLarge when multipart request exceeds size limits, returning HTTP 413 status code instead of HTTP 400 per RFC 7231.

Closes #4439

Description

Changes the exception raised when multipart requests exceed size limits from ClientException (HTTP 400) to RequestEntityTooLarge (HTTP 413).

Changes

  • Modified litestar/_multipart.py line 138 to use RequestEntityTooLarge
  • Added import for RequestEntityTooLarge
  • Added test to verify 413 status code

Why

HTTP 413 is the correct status code for "Request Entity Too Large" per RFC 7231, not 400 Bad Request.

Testing

  • Added new test: test_multipart_413.py
  • All existing tests pass

Closes 4439

@nclimaz nclimaz requested review from a team as code owners November 20, 2025 04:59
@github-actions github-actions bot added area/multipart area/private-api This PR involves changes to the privatized API size: small type/bug pr/external Triage Required 🏥 This requires triage labels Nov 20, 2025
Changed ClientException to RequestEntityTooLarge when multipart
request exceeds size limits, returning HTTP 413 status code
instead of HTTP 400 per RFC 7231.

Closes litestar-org#4439
@nclimaz nclimaz force-pushed the fix/multipart-413-error branch from 02e661d to 756d392 Compare November 20, 2025 05:10
@nclimaz nclimaz closed this Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/multipart area/private-api This PR involves changes to the privatized API pr/external size: small Triage Required 🏥 This requires triage type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: v3 abort request with 413 instead of 400 if request body is too large

1 participant