Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ type (
// If value is 0, rate limit is set default value.
RequestLimitTimeWindow uint64

// BodyLimit is a maximum size of request body.
// If value is 0, body limit is disabled.
BodyLimit uint64
// BodyLimit sets the maximum allowed size for the request body.
// If set to the empty string (`""`), no body size limit is enforced.
// Accepted formats are an integer followed by an optional unit, e.g. `4K`, `4KB`, `10M`, `1G`.
// Supported units: K, M, G, T, P (optionally followed by `B`), case-insensitive.
Comment thread
ziflex marked this conversation as resolved.
BodyLimit string
}

// Server is HTTP server that wraps Ferret worker.
Expand Down Expand Up @@ -76,8 +78,8 @@ func New(logger *lecho.Logger, opts Options) (*Server, error) {
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))

if opts.BodyLimit > 0 {
router.Use(middleware.BodyLimit(fmt.Sprintf("%d", opts.BodyLimit)))
if opts.BodyLimit != "" {
router.Use(middleware.BodyLimit(opts.BodyLimit))
Comment on lines +81 to +82
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BodyLimit middleware can panic if given an invalid format string. Consider adding validation for the BodyLimit string format before passing it to the middleware, or wrapping the middleware call in error handling. Valid formats should match the pattern: a number followed by an optional unit (K, KB, M, MB, G, GB, etc.). Invalid input like "invalid", "10X", or "-5M" could cause panics at startup.

Copilot uses AI. Check for mistakes.
}

router.Use(middleware.RequestID())
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ var (
"amount of seconds for request rate limit time window",
)

bodyLimit = flag.Uint64(
bodyLimit = flag.String(
"body-limit",
1000,
"maximum size of request body in kb. 0 means no limit.",
"1M",
"maximum allowed size for a request body (e.g., 4K, 4KB, 10M, 1G). Empty string means no limit.",
)

showVersion = flag.Bool(
Expand Down
Loading