Skip to content

Commit 4536d93

Browse files
authored
Update body limit configuration to support size units and improve documentation (#55)
1 parent b8c1639 commit 4536d93

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

internal/server/server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ type (
2626
// If value is 0, rate limit is set default value.
2727
RequestLimitTimeWindow uint64
2828

29-
// BodyLimit is a maximum size of request body.
30-
// If value is 0, body limit is disabled.
31-
BodyLimit uint64
29+
// BodyLimit sets the maximum allowed size for the request body.
30+
// If set to the empty string (`""`), no body size limit is enforced.
31+
// Accepted formats are an integer followed by an optional unit, e.g. `4K`, `4KB`, `10M`, `1G`.
32+
// Supported units: K, M, G, T, P (optionally followed by `B`), case-insensitive.
33+
BodyLimit string
3234
}
3335

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

79-
if opts.BodyLimit > 0 {
80-
router.Use(middleware.BodyLimit(fmt.Sprintf("%d", opts.BodyLimit)))
81+
if opts.BodyLimit != "" {
82+
router.Use(middleware.BodyLimit(opts.BodyLimit))
8183
}
8284

8385
router.Use(middleware.RequestID())

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ var (
5757
"amount of seconds for request rate limit time window",
5858
)
5959

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

6666
showVersion = flag.Bool(

0 commit comments

Comments
 (0)