mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-26 11:34:58 +02:00
make cache control header configurable
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
@@ -37,6 +37,8 @@ pub struct Config {
|
||||
|
||||
// store blobs inline if size is less than this
|
||||
pub inline_threshold: Size,
|
||||
|
||||
pub cache_control: String,
|
||||
}
|
||||
|
||||
pub mod hulyrs {
|
||||
@@ -65,6 +67,8 @@ pub static CONFIG: LazyLock<Config> = LazyLock::new(|| {
|
||||
|
||||
multipart_threshold = "4MB"
|
||||
inline_threshold = "100KB"
|
||||
|
||||
cache_control = "public, no-cache"
|
||||
"#;
|
||||
|
||||
let mut builder =
|
||||
|
||||
@@ -32,8 +32,6 @@ use crate::{
|
||||
};
|
||||
use crate::{merge::MergeStrategy, recovery};
|
||||
|
||||
const CACHE_CONTROL: &str = "public, max-age=0, must-revalidate";
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct ObjectPath {
|
||||
workspace: Uuid,
|
||||
@@ -384,7 +382,7 @@ pub async fn get(request: HttpRequest) -> HandlerResult<HttpResponse> {
|
||||
Some(false) => HttpResponse::NotModified()
|
||||
.insert_header((header::ETAG, etag))
|
||||
.insert_header((header::LAST_MODIFIED, HttpDate::from(date)))
|
||||
.insert_header((header::CACHE_CONTROL, CACHE_CONTROL))
|
||||
.insert_header((header::CACHE_CONTROL, CONFIG.cache_control.clone()))
|
||||
.finish(),
|
||||
_ => {
|
||||
let mut response = HttpResponse::Ok();
|
||||
@@ -404,7 +402,7 @@ pub async fn get(request: HttpRequest) -> HandlerResult<HttpResponse> {
|
||||
|
||||
response.insert_header((header::ETAG, etag));
|
||||
response.insert_header((header::LAST_MODIFIED, HttpDate::from(date)));
|
||||
response.insert_header((header::CACHE_CONTROL, CACHE_CONTROL));
|
||||
response.insert_header((header::CACHE_CONTROL, CONFIG.cache_control.clone()));
|
||||
response.body(merge::stream(s3, parts).await?)
|
||||
}
|
||||
}
|
||||
@@ -438,7 +436,7 @@ pub async fn head(request: HttpRequest) -> HandlerResult<HttpResponse> {
|
||||
Some(false) => HttpResponse::NotModified()
|
||||
.insert_header((header::ETAG, etag))
|
||||
.insert_header((header::LAST_MODIFIED, HttpDate::from(date)))
|
||||
.insert_header((header::CACHE_CONTROL, CACHE_CONTROL))
|
||||
.insert_header((header::CACHE_CONTROL, CONFIG.cache_control.clone()))
|
||||
.finish(),
|
||||
_ => {
|
||||
let mut response = HttpResponse::Ok();
|
||||
@@ -452,7 +450,7 @@ pub async fn head(request: HttpRequest) -> HandlerResult<HttpResponse> {
|
||||
|
||||
response.insert_header((header::ETAG, etag));
|
||||
response.insert_header((header::LAST_MODIFIED, HttpDate::from(date)));
|
||||
response.insert_header((header::CACHE_CONTROL, CACHE_CONTROL));
|
||||
response.insert_header((header::CACHE_CONTROL, CONFIG.cache_control.clone()));
|
||||
|
||||
// see https://github.com/actix/examples/blob/master/forms/multipart-s3/src/main.rs#L67-L79
|
||||
let content_length = merge::content_length(parts);
|
||||
|
||||
Reference in New Issue
Block a user