Skip to content

Update body limit configuration to support size units#55

Merged
ziflex merged 1 commit intomasterfrom
fix/body-limit
Feb 5, 2026
Merged

Update body limit configuration to support size units#55
ziflex merged 1 commit intomasterfrom
fix/body-limit

Conversation

@ziflex
Copy link
Member

@ziflex ziflex commented Feb 5, 2026

This pull request updates the way the server handles request body size limits by switching from a numeric value in kilobytes to a more flexible string-based format that supports various units (e.g., K, M, G). This allows users to specify body size limits in a more intuitive way and aligns the configuration across the codebase.

Body size limit configuration improvements:

  • Changed the BodyLimit field in the Options struct from a uint64 (kilobytes) to a string that accepts values like 4K, 10M, or 1G, with an empty string disabling the limit.
  • Updated the server initialization logic to use the new string-based BodyLimit directly, removing the need for formatting or conversion.
  • Modified the command-line flag for body-limit from a uint64 to a string, updating the default value and help text to reflect the new, more flexible format.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request updates the request body size limit configuration from a numeric value in kilobytes to a more flexible string-based format that supports size units (K, M, G, etc.). Critically, this PR also fixes a bug where the previous implementation was incorrectly treating the numeric value as bytes rather than kilobytes, resulting in a much more restrictive limit than documented.

Changes:

  • Changed the BodyLimit field type from uint64 to string to support unit-based size specifications (e.g., "1M", "4K", "10M")
  • Updated the command-line flag from flag.Uint64 to flag.String with a new default value of "1M"
  • Modified the conditional check from numeric comparison to empty string check
  • Removed the fmt.Sprintf formatting since the string value is now passed directly to Echo's middleware

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
main.go Updated the body-limit flag from uint64 to string type, changed default from 1000 to "1M", and updated help text to reflect the new format with examples
internal/server/server.go Changed BodyLimit field in Options struct from uint64 to string, updated documentation to describe supported formats and units, and modified the middleware initialization to use the string value directly

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +81 to +82
if opts.BodyLimit != "" {
router.Use(middleware.BodyLimit(opts.BodyLimit))
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.
@ziflex ziflex merged commit 4536d93 into master Feb 5, 2026
10 checks passed
@ziflex ziflex deleted the fix/body-limit branch February 5, 2026 02:31
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.

2 participants