Skip to content

Commit

Permalink
feat(rust): disable HTTP caching
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 10, 2025
1 parent d4771bd commit cc69ca8
Show file tree
Hide file tree
Showing 2 changed files with 13 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)
}
}

0 comments on commit cc69ca8

Please sign in to comment.