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 * 1024
Hardcoded 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() in gateway/config.go.
- Read
MAX_REQUEST_BODY_MB (int).
- Default to
10.
- Return bytes (
val * 1024 * 1024).
- Update Handler: Replace the
const maxBodySize in handleSummarize with 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
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 Large
Problem
The Gateway currently enforces a hardcoded request body size limit of 10MB in
gateway/main.go.Hardcoded 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_MBwith a default value of 10.Implementation
getMaxBodySize()ingateway/config.go.MAX_REQUEST_BODY_MB(int).10.val * 1024 * 1024).const maxBodySizeinhandleSummarizewith the dynamic value from the helper..env.example.Code Hint
Acceptance Criteria
MAX_REQUEST_BODY_MBenvironment variable controls the limit..env.exampleincludes the new variable.Testing