Skip to content

feat: implement client_max_body_size validation for upload limits#64

Merged
jos-felipe merged 1 commit intomainfrom
jos-felipe/feature-upload-size-limits
Aug 24, 2025
Merged

feat: implement client_max_body_size validation for upload limits#64
jos-felipe merged 1 commit intomainfrom
jos-felipe/feature-upload-size-limits

Conversation

@jos-felipe
Copy link
Copy Markdown
Owner

Summary

  • Implements proper validation for the client_max_body_size configuration directive (10MB limit)
  • Adds early request rejection for oversized uploads with HTTP 413 Payload Too Large responses
  • Supports validation for both regular POST requests and chunked transfer encoding

Changes Made

  • HttpRequest.hpp/cpp: Added server config reference and size validation methods
  • Server.cpp: Updated to pass server configuration to request parsing
  • test_upload_limits.sh: Comprehensive test suite covering all upload scenarios

Validation Points

  1. Early Header Validation: Rejects requests with Content-Length > limit immediately
  2. Incremental Body Validation: Checks accumulated body size during parsing
  3. Chunked Transfer Validation: Validates chunk-by-chunk accumulation
  4. Error Response: Returns proper 413 status with error page

Test Coverage

  • ✅ Small file uploads (success cases)
  • ✅ Large file uploads (rejection cases)
  • ✅ Boundary file uploads (exactly at limit)
  • ✅ Chunked transfer encoding
  • ✅ Content-Length header validation
  • ✅ Multipart form-data uploads

All tests pass and validate proper HTTP/1.1 compliance for request size limits.

- Add server config reference to HttpRequest for size validation
- Implement early validation in parseHeaders() for Content-Length
- Add incremental size checks in parseBody() and parseChunkedData()
- Return 413 Payload Too Large for requests exceeding limit
- Add comprehensive test suite for upload size limit scenarios
- Support both regular and chunked transfer encoding validation
@jos-felipe jos-felipe merged commit e4410bc into main Aug 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant