use actix_web::HttpRequest;
pub fn is_cache_control_no_cache(req: &HttpRequest) -> bool {
req.headers()
.get("Cache-Control")
.map_or(false, |value| value == "no-cache")
}
#[cfg(test)]
mod tests {
use super::*;
use actix_web::test::TestRequest;
#[actix_web::test]
async fn test_no_cache_true_when_header_present() {
let req = TestRequest::default()
.insert_header(("Cache-Control", "no-cache"))
.to_http_request();
assert!(is_cache_control_no_cache(&req));
}
#[actix_web::test]
async fn test_no_cache_false_when_header_missing() {
let req = TestRequest::default().to_http_request();
assert!(!is_cache_control_no_cache(&req));
}
#[actix_web::test]
async fn test_no_cache_false_other_directives() {
let req = TestRequest::default()
.insert_header(("Cache-Control", "max-age=60"))
.to_http_request();
assert!(!is_cache_control_no_cache(&req));
}
}