-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Labels
Description
Problem
The Gateway currently enforces a hardcoded request body size limit of 10MB in gateway/main.go.
// gateway/main.go line ~363
const maxBodySize = 10 * 1024 * 1024Hardcoded limits are an anti-pattern for production services. Different deployments may need to handle larger documents for summarization or, conversely, restrict payloads to very small sizes to prevent DoS attacks on memory.
Solution
Refactor this constant into an environment variable MAX_REQUEST_BODY_MB with a default value of 10.
Implementation
- Add Helper: Add a configuration helper
getMaxBodySize()ingateway/config.go.- Read
MAX_REQUEST_BODY_MB(int). - Default to
10. - Return bytes (
val * 1024 * 1024).
- Read
- Update Handler: Replace the
const maxBodySizeinhandleSummarizewith the dynamic value from the helper. - Update Documentation: Add the new variable to
.env.example.
Code Hint
// gateway/config.go
func getMaxBodySize() int64 {
mb := getEnvAsInt("MAX_REQUEST_BODY_MB", 10)
return int64(mb) * 1024 * 1024
}
// gateway/main.go
func handleSummarize(c *gin.Context) {
// ...
maxSize := getMaxBodySize()
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxSize)
// ...
}Acceptance Criteria
-
MAX_REQUEST_BODY_MBenvironment variable controls the limit. - Default remains 10MB if variable is unset.
-
.env.exampleincludes the new variable.
Testing
# 1. Set MAX_REQUEST_BODY_MB=1 in .env
# 2. Restart Gateway
# 3. Send a 2MB payload
curl -X POST localhost:3000/api/ai/summarize -d @large_file.json
# Expect: 413 Request Entity Too LargeReactions are currently unavailable