feat: cache control headers optional via `--cache-control-headers`
Diff
src/config.rs | 10 ++++++++++
src/handler.rs | 5 ++++-
src/server.rs | 5 +++++
3 files changed, 19 insertions(+), 1 deletion(-)
@@ -131,4 +131,14 @@ pub struct Config {
pub security_headers: bool,
#[structopt(
long,
short = "e",
parse(try_from_str),
default_value = "true",
env = "SERVER_CACHE_CONTROL_HEADERS"
)]
pub cache_control_headers: bool,
}
@@ -12,6 +12,7 @@ pub struct RequestHandlerOpts {
pub dir_listing: bool,
pub cors: Option<Arc<cors::Configured>>,
pub security_headers: bool,
pub cache_control_headers: bool,
pub page404: Arc<str>,
pub page50x: Arc<str>,
}
@@ -74,7 +75,9 @@ impl RequestHandler {
}
control_headers::append_headers(&uri_path, &mut resp);
if self.opts.cache_control_headers {
control_headers::append_headers(&uri_path, &mut resp);
}
if self.opts.security_headers {
@@ -102,6 +102,10 @@ impl Server {
let dir_listing = opts.directory_listing;
tracing::info!("directory listing: enabled={}", dir_listing);
let cache_control_headers = opts.cache_control_headers;
tracing::info!("cache control headers: enabled={}", cache_control_headers);
let cors = cors::new(opts.cors_allow_origins.trim().to_owned());
@@ -113,6 +117,7 @@ impl Server {
dir_listing,
cors,
security_headers,
cache_control_headers,
page404,
page50x,
},