-
Notifications
You must be signed in to change notification settings - Fork 57
feat(gateway): make request body size limit configurable via MAX_REQUEST_BODY_BYTES #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -337,6 +337,7 @@ Core local variables live in [.env.example](.env.example). Production placeholde | |
| | `METRICS_PATH` | Gateway | Gateway metrics path. Default `/metrics`; values without a leading slash are normalized. | | ||
| | `ALLOWED_ORIGINS` | Gateway | Comma-separated CORS origins, no paths or query strings. | | ||
| | `TRUSTED_PROXIES` | Gateway | Comma-separated trusted proxy CIDRs for production IP handling. | | ||
| | `MAX_REQUEST_BODY_BYTES` | Gateway | Maximum request body size in bytes for `POST /api/ai/summarize`. Default `10485760` (10 MB). | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This new root README entry documents the knob, but the gateway service README still has its own environment table and does not mention Useful? React with 👍 / 👎.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The production path points operators at Useful? React with 👍 / 👎. |
||
| | `NEXT_PUBLIC_GATEWAY_URL` | Web | Gateway base URL. Browser fetches `/api/ai/summarize` and `/api/receipts/:id` here. | | ||
| | `NEXT_PUBLIC_EXPECTED_CHAIN_ID` | Web | Chain ID the wallet widget targets. Must match the gateway's `CHAIN_ID`. Default `84532`. | | ||
| | `NEXT_PUBLIC_EXPECTED_CHAIN_NAME` | Web | Display name paired with the chain ID — used by the wallet widget's "Switch to <name>" button, hero headline, stat bar, and page title. Must be set when `CHAIN_ID` is overridden (e.g. `Base` for `8453`). | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -474,3 +474,85 @@ func TestGetReceiptTTL(t *testing.T) { | |
| func stringPtr(value string) *string { | ||
| return &value | ||
| } | ||
|
|
||
| func TestGetMaxRequestBodySize(t *testing.T) { | ||
| t.Run("default when unset", func(t *testing.T) { | ||
| t.Setenv("MAX_REQUEST_BODY_BYTES", "") | ||
| got := getMaxRequestBodySize() | ||
| want := int64(10 * 1024 * 1024) | ||
| if got != want { | ||
| t.Fatalf("expected default %d, got %d", want, got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("custom value", func(t *testing.T) { | ||
| t.Setenv("MAX_REQUEST_BODY_BYTES", "5242880") | ||
| got := getMaxRequestBodySize() | ||
| want := int64(5 * 1024 * 1024) | ||
| if got != want { | ||
| t.Fatalf("expected %d, got %d", want, got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("zero falls back to default", func(t *testing.T) { | ||
| t.Setenv("MAX_REQUEST_BODY_BYTES", "0") | ||
| got := getMaxRequestBodySize() | ||
| want := int64(10 * 1024 * 1024) | ||
| if got != want { | ||
| t.Fatalf("expected default %d for zero, got %d", want, got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("negative falls back to default", func(t *testing.T) { | ||
| t.Setenv("MAX_REQUEST_BODY_BYTES", "-100") | ||
| got := getMaxRequestBodySize() | ||
| want := int64(10 * 1024 * 1024) | ||
| if got != want { | ||
| t.Fatalf("expected default %d for negative, got %d", want, got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("invalid string falls back to default", func(t *testing.T) { | ||
| t.Setenv("MAX_REQUEST_BODY_BYTES", "not-a-number") | ||
| got := getMaxRequestBodySize() | ||
| want := int64(10 * 1024 * 1024) | ||
| if got != want { | ||
| t.Fatalf("expected default %d for invalid string, got %d", want, got) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("small value 1024", func(t *testing.T) { | ||
| t.Setenv("MAX_REQUEST_BODY_BYTES", "1024") | ||
| got := getMaxRequestBodySize() | ||
| want := int64(1024) | ||
| if got != want { | ||
| t.Fatalf("expected %d, got %d", want, got) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func TestFormatBytes(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input int64 | ||
| want string | ||
| }{ | ||
| {"10MB", 10 * 1024 * 1024, "10MB"}, | ||
| {"1MB", 1 * 1024 * 1024, "1MB"}, | ||
| {"5MB", 5 * 1024 * 1024, "5MB"}, | ||
| {"512KB", 512 * 1024, "512KB"}, | ||
| {"1KB", 1024, "1KB"}, | ||
| {"odd bytes", 1500, "1500 bytes"}, | ||
| {"zero bytes", 0, "0 bytes"}, | ||
| {"100MB", 100 * 1024 * 1024, "100MB"}, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := formatBytes(tt.input) | ||
| if got != tt.want { | ||
| t.Fatalf("formatBytes(%d) = %q, want %q", tt.input, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The repository instructions require Go changes to be gofmt-clean, but this added trailing blank line makes Useful? React with 👍 / 👎. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When users follow the documented Docker Compose flow and uncomment/set this value in the root
.env, the gateway container still will not see it because thedocker-compose.ymlgatewayenvironmentlist only passes selected variables and omitsMAX_REQUEST_BODY_BYTES(checkeddocker-compose.ymllines 8-26). As a result Compose deployments keep using the 10MB default despite the new.env.example/README setting; add this variable to the gateway service environment so the advertised configuration works there too.Useful? React with 👍 / 👎.