Skip to content

fix: use registered root for relative downloads - #610

Open
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/download-use-registered-root-20260829
Open

fix: use registered root for relative downloads#610
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/download-use-registered-root-20260829

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown

Problem

When @fastify/static is registered with a root, reply.download() returns a 404 for a relative file path such as reply.download('myHtml.html'). The README documents this relative form, and the equivalent relative reply.sendFile() call serves successfully; the download response still sets Content-Disposition before failing.

Fix

Use the registered plugin root when download() is not given a per-call root, matching the existing sendFile() behavior. Explicit per-call roots continue to take precedence.

Tests

  • node --test --test-name-pattern='download' test/static.test.js — passed; 10 tests. The same focused test failed on the new regression case before the fix.
  • npm test — passed; 347 unit tests, 100% reported coverage, 20/20 TypeScript assertions.
  • npm run lint — passed.
  • npm run benchmark --if-present — passed; no benchmark script is defined.
  • node --check index.js && node --check test/static.test.js — passed.
  • git diff HEAD^ HEAD --check — passed.

Compatibility

This only supplies the registration root when no per-call root is supplied. Existing absolute paths, explicit roots, options, and response headers remain unchanged. No dependencies or package versions were changed.

Related issue

Independent reproduction; no matching open issue or pull request was found.

Signed-off-by: lprnmns <manasalperen@gmail.com>
@lprnmns
lprnmns marked this pull request as ready for review August 31, 2026 16:20
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.

1 participant