cache control

This commit is contained in:
realaravinth 2021-05-30 17:55:11 +05:30
parent 1aaf362b0c
commit 2ea818591e
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
3 changed files with 18 additions and 9 deletions

View file

@ -1,2 +1,5 @@
[target.aarch64-unknown-linux-musl]
image = "realaravinth/cross:aarch64-unknown-linux-musl-postgres"
[build.env]
passthrough = [
"RUST_BACKTRACE",
"RUST_LOG",
]

View file

@ -86,7 +86,7 @@ pub static PKG_NAME: &str = env!("CARGO_PKG_NAME");
pub static PKG_DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
pub static PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");
pub const CACHE_AGE: u32 = 365 * 24 * 3600;
pub const CACHE_AGE: u32 = 604800;
#[cfg(not(tarpaulin_include))]
#[actix_web::main]

View file

@ -37,9 +37,12 @@ fn handle_assets(path: &str) -> HttpResponse {
};
HttpResponse::Ok()
.set(header::CacheControl(vec![header::CacheDirective::MaxAge(
CACHE_AGE,
)]))
.set(header::CacheControl(
vec![
header::CacheDirective::Public,
header::CacheDirective::Extension("immutable".into(), None),
header::CacheDirective::MaxAge(CACHE_AGE)
]))
.content_type(from_path(path).first_or_octet_stream().as_ref())
.body(body)
}
@ -67,9 +70,12 @@ fn handle_favicons(path: &str) -> HttpResponse {
};
HttpResponse::Ok()
.set(header::CacheControl(vec![header::CacheDirective::MaxAge(
CACHE_AGE,
)]))
.set(header::CacheControl(
vec![
header::CacheDirective::Public,
header::CacheDirective::Extension("immutable".into(), None),
header::CacheDirective::MaxAge(CACHE_AGE)
]))
.content_type(from_path(path).first_or_octet_stream().as_ref())
.body(body)
}