Skip to content

fix: use registered root for relative downloads - #610

Merged
Tony133 merged 2 commits into
fastify:mainfrom
lprnmns:fix/download-use-registered-root-20260829
Sep 25, 2026
Merged

Tony133 merged 2 commits into
fastify:mainfrom
lprnmns:fix/download-use-registered-root-20260829

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

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
Signed-off-by: lprnmns <manasalperen@gmail.com>
@ilteoood
ilteoood self-requested a review September 25, 2026 13:13
@ilteoood
ilteoood requested a review from a team September 25, 2026 13:13
@Tony133
Tony133 merged commit 275d87e into fastify:main Sep 25, 2026
17 checks passed
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.

3 participants