diff --git a/.changes/updater-http-cache-fixes.md b/.changes/updater-http-cache-fixes.md new file mode 100644 index 0000000000..3b2cc4d9fe --- /dev/null +++ b/.changes/updater-http-cache-fixes.md @@ -0,0 +1,6 @@ +--- +updater: patch +updater-js: patch +--- + +Updated HTTP cache dependencies to fix stale response handling during revalidation and send `Cache-Control: no-cache` on cache misses when using `checkNow`. These fixes apply when the `cache` feature is enabled. diff --git a/.changes/updater-http-cache.md b/.changes/updater-http-cache.md new file mode 100644 index 0000000000..afb6a4ca84 --- /dev/null +++ b/.changes/updater-http-cache.md @@ -0,0 +1,10 @@ +--- +"updater": minor +"updater-js": minor +--- + +- Added an in-memory HTTP cache for update checks (downloads are not cached), behind the new `cache` cargo feature (disabled by default). Without it, caching is compiled out and `cacheMode` has no effect. +- New `plugins.updater.cache` config: `enabledByDefault` and `maxTtlMins` (defaults to 12 hours). +- The JS `check` command has a new `cacheMode` option (`default`, `bypass`, `checkNow`). In Rust this is exposed as `UpdaterBuilder::cache_mode_override`. +- **Behavior change:** Caching is opt-in in this release. You can opt-in with `check({cacheMode: 'checkNow'})`, `cacheMode: 'default'` or set `enabledByDefault = true`. Otherwise the updater behaves the same and transparently skips caching. This is intended as temporary and a future release is expected to change the default! +- **Rust API change:** Network errors from `check()` now come back as `Error::ReqwestMiddleware(Reqwest(..))` instead of `Error::Reqwest`, so code that matches on the old variant stops matching. diff --git a/Cargo.lock b/Cargo.lock index 8b9c7a957c..d057126004 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -302,7 +302,7 @@ dependencies = [ "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", - "windows-sys 0.52.0", + "windows-sys 0.60.2", "wl-clipboard-rs", "x11rb", ] @@ -1027,6 +1027,15 @@ dependencies = [ "error-code", ] +[[package]] +name = "cobs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror 2.0.12", +] + [[package]] name = "colorchoice" version = "1.0.3" @@ -1565,7 +1574,7 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.0", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -1801,6 +1810,18 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "encoding_rs" version = "0.8.35" @@ -1870,7 +1891,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2704,12 +2725,11 @@ dependencies = [ [[package]] name = "http" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" dependencies = [ "bytes", - "fnv", "itoa", ] @@ -2736,12 +2756,85 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-cache" +version = "1.0.0-alpha.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f73227598c305455fc0ca3a601e6d842ba4476f3db2c76d24d821005b93f7db" +dependencies = [ + "bytes", + "http", + "http-body", + "http-cache-semantics", + "httpdate", + "log", + "pin-project-lite", + "postcard", + "serde", + "url", +] + +[[package]] +name = "http-cache-quickcache" +version = "1.0.0-alpha.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ac0d2fc7dfe8acb5a59875ac449ebf92bcb425a1bb569f1d8598c4cda4daf5f" +dependencies = [ + "http", + "http-cache", + "http-cache-semantics", + "postcard", + "quick_cache", + "serde", +] + +[[package]] +name = "http-cache-reqwest" +version = "1.0.0-alpha.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d88c679f570367a474b098da5986d115008951ed8ad0437f8790cda31c3f7d86" +dependencies = [ + "anyhow", + "async-trait", + "bytes", + "http", + "http-body", + "http-body-util", + "http-cache", + "http-cache-semantics", + "reqwest 0.13.5", + "reqwest-middleware", + "url", +] + +[[package]] +name = "http-cache-semantics" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0603b99309a1e404c2c0945650c0f775b50bb72ac90ae570cb93f9ff05d9efe7" +dependencies = [ + "http", + "http-serde", + "serde", + "time", +] + [[package]] name = "http-range" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573" +[[package]] +name = "http-serde" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f056c8559e3757392c8d091e796416e4649d8e49e88b8d76df6c002f05027fd" +dependencies = [ + "http", + "serde", +] + [[package]] name = "httparse" version = "1.10.1" @@ -2839,7 +2932,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.5.9", + "socket2 0.6.5", "system-configuration", "tokio", "tower-service", @@ -3776,7 +3869,7 @@ dependencies = [ "png 0.18.1", "serde", "thiserror 2.0.12", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -4783,6 +4876,18 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "postcard" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" +dependencies = [ + "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", + "serde", +] + [[package]] name = "potential_utf" version = "0.1.4" @@ -4914,6 +5019,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "quick_cache" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403c1a912fec895cafb223201e368234842acb9220aaf08ab042ae89ba5f135c" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", +] + [[package]] name = "quinn" version = "0.11.7" @@ -4967,7 +5082,7 @@ dependencies = [ "once_cell", "socket2 0.5.9", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5247,6 +5362,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "reqwest-middleware" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc3f1384cffa4f274dad2d4ddd73aed32fed8f786d96c6be8aa4e5fd3c3b58" +dependencies = [ + "anyhow", + "async-trait", + "http", + "reqwest 0.13.5", + "thiserror 2.0.12", + "tower-service", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -5409,7 +5538,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5422,7 +5551,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -5479,7 +5608,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -5977,7 +6106,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -7170,13 +7299,19 @@ dependencies = [ "flate2", "futures-util", "http", + "http-cache", + "http-cache-quickcache", + "http-cache-reqwest", "infer", "libc", "log", "minisign-verify 0.3.0", + "mockito", "osakit", "percent-encoding", + "quick_cache", "reqwest 0.13.5", + "reqwest-middleware", "rustls", "semver", "serde", @@ -7364,7 +7499,7 @@ dependencies = [ "getrandom 0.3.2", "once_cell", "rustix 1.1.6", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -7803,7 +7938,7 @@ dependencies = [ "png 0.18.1", "serde", "thiserror 2.0.12", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -8492,7 +8627,7 @@ dependencies = [ "objc2-foundation 0.3.2", "objc2-quartz-core 0.3.2", "raw-window-handle", - "windows-sys 0.61.2", + "windows-sys 0.60.2", "windows-version", ] diff --git a/examples/api/src-tauri/tauri.conf.json b/examples/api/src-tauri/tauri.conf.json index 72c333953c..de215f71aa 100644 --- a/examples/api/src-tauri/tauri.conf.json +++ b/examples/api/src-tauri/tauri.conf.json @@ -91,7 +91,11 @@ "endpoints": [ "http://localhost:5173/updater-test/updater.json", "https://tauri-update-server.vercel.app/update/{{target}}/{{current_version}}" - ] + ], + "cache": { + "enabledByDefault": true, + "maxTtlMins": 180 + } } }, "bundle": { diff --git a/examples/api/src/views/Updater.svelte b/examples/api/src/views/Updater.svelte index 5fdc775095..18a2fb696d 100644 --- a/examples/api/src/views/Updater.svelte +++ b/examples/api/src/views/Updater.svelte @@ -1,10 +1,11 @@ -