Skip to content

fix(sftp): stop the browser cache from serving a stale download - #355

Merged
FloSch62 merged 1 commit into
FloSch62:mainfrom
antoinekh:fix/sftp-download-cache
Nov 9, 2026
Merged

FloSch62 merged 1 commit into
FloSch62:mainfrom
antoinekh:fix/sftp-download-cache

Conversation

@antoinekh

Copy link
Copy Markdown
Contributor

Fixes #354

Problem

After a remote file is rewritten under the same path, downloading it again from the SFTP panel returns the previous content. The editor's Download button and Open locally are affected the same way; with Open locally, saving the file back then fails with SFTP_FILE_CHANGED.

Cause

GET /api/sftp/:connId/download sends Last-Modified but no Cache-Control, and the client fetches it with a plain fetch(). The response is then heuristically fresh (RFC 9111 §4.2.2): Chromium serves it from the HTTP cache for 10% of the file's age without asking the server, so about 12 hours for a file last changed 5 days ago.

Fix

The route now sends cache-control: no-store, as /api/sftp/:connId/drag-download already does. Last-Modified stays: Open locally still reads it for its upload check.

Testing

  • The existing download route test now also checks the cache-control header. It fails without the change (expected undefined to be 'no-store') and passes with it.
  • pnpm typecheck and pnpm lint pass.
  • pnpm test: 2463 tests pass. The only failing suite is unit/electron/web-windows.test.ts, because the Electron binary download failed on my machine (Electron failed to install correctly); it is unrelated to this change.
  • Not tested in the desktop app.

@FloSch62

FloSch62 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Thanks! @antoinekh

@FloSch62
FloSch62 merged commit 1e36106 into FloSch62:main Nov 9, 2026
5 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.

SFTP download returns a stale copy after the remote file changes

2 participants