Skip to content

Commit

Permalink
feat(rust): disable HTTP caching (#1880)
Browse files Browse the repository at this point in the history
## Problem

When connecting to the same machine (e.g. a server) but using a
different version of Agama (e.g., you are using a new build), the
browser cache could display the old UI.

## Solution

Disable the cache by setting the `no-store` value. In the future, we
could prefer using a different mechanism, like the `Etag` header.

## Testing

- *Tested manually*
  • Loading branch information
imobachgs authored Jan 10, 2025
2 parents 46a4610 + 9a58bf8 commit 9ac7280
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rust/agama-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ macaddr = { version = "1.0", features = ["serde_std"] }
async-trait = "0.1.83"
axum = { version = "0.7.7", features = ["ws"] }
serde_json = "1.0.128"
tower-http = { version = "0.5.2", features = ["compression-br", "fs", "trace"] }
tower-http = { version = "0.5.2", features = [
"compression-br",
"fs",
"trace",
"set-header",
] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-journald = "0.3.0"
tracing = "0.1.40"
Expand Down
7 changes: 7 additions & 0 deletions rust/agama-server/src/web/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use super::http::{login, login_from_query, logout, session};
use super::{config::ServiceConfig, state::ServiceState, EventsSender};
use agama_lib::auth::TokenClaims;
use axum::http::HeaderValue;
use axum::{
body::Body,
extract::Request,
Expand All @@ -29,12 +30,14 @@ use axum::{
routing::{get, post},
Router,
};
use hyper::header::CACHE_CONTROL;
use std::time::Duration;
use std::{
convert::Infallible,
path::{Path, PathBuf},
};
use tower::Service;
use tower_http::set_header::SetResponseHeaderLayer;
use tower_http::{compression::CompressionLayer, services::ServeDir, trace::TraceLayer};
use tracing::Span;

Expand Down Expand Up @@ -128,6 +131,10 @@ impl MainServiceBuilder {
),
)
.layer(CompressionLayer::new().br(true))
.layer(SetResponseHeaderLayer::if_not_present(
CACHE_CONTROL,
HeaderValue::from_static("no-store"),
))
.with_state(state)
}
}
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Fri Jan 10 08:58:29 UTC 2025 - Imobach Gonzalez Sosa <[email protected]>

- Disable the browser cache setting the "Cache-Control" header to
"no-store" (gh#agama-project/agama#1880).

-------------------------------------------------------------------
Thu Jan 9 12:52:05 UTC 2025 - Josef Reidinger <[email protected]>

Expand Down

0 comments on commit 9ac7280

Please sign in to comment.