mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Allow caching all GET requests
This commit is contained in:
parent
6efab9aab1
commit
e8a5b9afe3
1 changed files with 5 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
use actix_web::{
|
||||
body::MessageBody,
|
||||
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
|
||||
http::header::CACHE_CONTROL,
|
||||
http::header::CACHE_CONTROL,http::Method,
|
||||
Error,
|
||||
HttpMessage,
|
||||
};
|
||||
|
@ -77,16 +77,17 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let req_method = req.method().clone();
|
||||
let mut res = svc.call(req).await?;
|
||||
|
||||
// Add cache-control header if none is present
|
||||
if !res.headers().contains_key(CACHE_CONTROL) {
|
||||
// If user is authenticated, mark as private. Otherwise cache
|
||||
// up to one minute.
|
||||
let cache_value = if jwt.is_some() {
|
||||
"private"
|
||||
} else {
|
||||
let cache_value = if jwt.is_none() || req_method == Method::GET {
|
||||
"public, max-age=60"
|
||||
} else {
|
||||
"private"
|
||||
};
|
||||
res
|
||||
.headers_mut()
|
||||
|
|
Loading…
Reference in a new issue