aboutsummaryrefslogtreecommitdiff
path: root/src/filters/files.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-04-30 01:59:13 +0200
committermetamuffin <metamuffin@disroot.org>2024-04-30 01:59:13 +0200
commitfcc558d8e1c6759c19adc81c55bbe6b0a1a0ee35 (patch)
tree5f13bd3215828ca4e92fcde641abfff8c11bb4aa /src/filters/files.rs
parentf57e6a8e8977d1acdfafeda7b1444cb155730894 (diff)
downloadgnix-fcc558d8e1c6759c19adc81c55bbe6b0a1a0ee35.tar
gnix-fcc558d8e1c6759c19adc81c55bbe6b0a1a0ee35.tar.bz2
gnix-fcc558d8e1c6759c19adc81c55bbe6b0a1a0ee35.tar.zst
sest cache control header
Diffstat (limited to 'src/filters/files.rs')
-rw-r--r--src/filters/files.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/filters/files.rs b/src/filters/files.rs
index 59de2f3..0b313e2 100644
--- a/src/filters/files.rs
+++ b/src/filters/files.rs
@@ -1,7 +1,13 @@
-use crate::{config::FileserverConfig, ServiceError};
+use crate::{
+ config::{CacheConfig, FileserverConfig},
+ ServiceError,
+};
use bytes::{Bytes, BytesMut};
use futures_util::{future, future::Either, ready, stream, FutureExt, Stream, StreamExt};
-use headers::{AcceptRanges, ContentLength, ContentRange, ContentType, HeaderMapExt, LastModified};
+use headers::{
+ AcceptRanges, CacheControl, ContentLength, ContentRange, ContentType, HeaderMapExt,
+ LastModified,
+};
use http_body_util::{combinators::BoxBody, BodyExt, StreamBody};
use humansize::FormatSizeOptions;
use hyper::{
@@ -139,6 +145,12 @@ pub async fn serve_files(
let mime = mime_guess::from_path(path).first_or_octet_stream();
r.headers_mut().typed_insert(ContentType::from(mime));
+ r.headers_mut().typed_insert(match config.cache {
+ CacheConfig::Public => CacheControl::new().with_public(),
+ CacheConfig::Private => CacheControl::new().with_private(),
+ CacheConfig::NoStore => CacheControl::new().with_no_store(),
+ });
+
// if config.etag {
// r.headers_mut().typed_insert(etag);
// }