Skip to content

Make HTTP body length tunable at runtime via APP_HTTP_MAX_BODY_LENGTH - #266

Merged
Clivern merged 1 commit into
Clivern:mainfrom
ngdangdat:feat/runtime-http-body-length
Apr 29, 2026
Merged

Make HTTP body length tunable at runtime via APP_HTTP_MAX_BODY_LENGTH#266
Clivern merged 1 commit into
Clivern:mainfrom
ngdangdat:feat/runtime-http-body-length

Conversation

@ngdangdat

@ngdangdat ngdangdat commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #265. The existing APP_HTTP_MAX_BODY_LENGTH env var is read via Application.compile_env, so it only takes effect at build time — flipping it on a running release has no impact. This PR makes it actually runtime-tunable, so operators can resize the limit by restarting the container with a different env value (no rebuild).

What changed

  • New Lynx.Config.max_body_length/0 reads :http_max_body_length from app env with an 8 MB fallback.
  • New LynxWeb.Plug.RuntimeParsers wraps Plug.Parsers and resolves length inside its own init/1 (so the value is fetched after runtime.exs runs).
  • Endpoint now uses the wrapper instead of Plug.Parsers directly; the @max_body_length module attribute is gone.
  • config :phoenix, :plug_init_mode, :runtime so endpoint plug init/1 callbacks run at endpoint boot rather than at module compile.
  • config/runtime.exs reads APP_HTTP_MAX_BODY_LENGTH and writes it into the endpoint config.
  • Default behavior unchanged: 8 MB when the env var is unset.

PoW

The state file is uploaded successfully. Dummy lock ID is used so Bad Request is expected.

  • Environment variable is set to 50MiB
  • Default value is 8MiB
  • Dummy test file is 15MiB (should be failed if 8MiB is used for the configuration).
curl -v -X POST \
  -u "$USERNAME:$PASSWORD" \
  -H "Content-Type: application/json" \
  --data-binary @/tmp/15mb.bin \
  "https://${DOMAIN}/client/***/***/dev/state?ID=00000000-0000-0000-0000-000000000000"
....
* upload completely sent off: 15728640 bytes
...
<
Bad Request%

@ngdangdat
ngdangdat marked this pull request as ready for review April 29, 2026 14:00
@ngdangdat
ngdangdat requested a review from Clivern as a code owner April 29, 2026 14:00
@ngdangdat

Copy link
Copy Markdown
Contributor Author

@Clivern I'm very sorry for not testing the change carefully in the last PR 🙇. For this one, I built an image myself and tested if the change works. The result is put in PoW section of the PR.

@Clivern Clivern left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm

@Clivern
Clivern merged commit ab61196 into Clivern:main Apr 29, 2026
8 checks passed
Clivern added a commit that referenced this pull request Apr 29, 2026
@ngdangdat
ngdangdat deleted the feat/runtime-http-body-length branch April 30, 2026 00:18
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