Skip to content

Commit 69b227a

Browse files
committed
Added a must-revalidate flag
The must-revalidate flag will force the browser to revalidate even if the age is within the expiry. This is useful for serving web applications which tend to change frequently.
1 parent 40fde04 commit 69b227a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ fn main() {
8282
.arg(clap::Arg::with_name("nocache")
8383
.long("nocache")
8484
.help("Disable http cache"))
85+
.arg(clap::Arg::with_name("must-revalidate")
86+
.long("must-revalidate")
87+
.help("Force revalidation"))
8588
.arg(clap::Arg::with_name("norange")
8689
.long("norange")
8790
.help("Disable header::Range support (partial request)"))
@@ -230,6 +233,7 @@ fn main() {
230233
.map(Result::unwrap);
231234
let sort = !matches.is_present("nosort");
232235
let cache = !matches.is_present("nocache");
236+
let must_revalidate = matches.is_present("must-revalidate") && !cache;
233237
let range = !matches.is_present("norange");
234238
let cert = matches.value_of("cert");
235239
let certpass = matches.value_of("certpass");
@@ -307,6 +311,7 @@ fn main() {
307311
&vec![
308312
enable_string(index),
309313
enable_string(cache),
314+
enable_string(must_revalidate),
310315
enable_string(cors),
311316
enable_string(coop),
312317
enable_string(coep),
@@ -351,6 +356,7 @@ fn main() {
351356
index,
352357
upload,
353358
cache,
359+
must_revalidate,
354360
range,
355361
coop,
356362
coep,
@@ -435,6 +441,7 @@ struct MainHandler {
435441
index: bool,
436442
upload: Option<Upload>,
437443
cache: bool,
444+
must_revalidate: bool,
438445
range: bool,
439446
coop: bool,
440447
coep: bool,
@@ -1070,7 +1077,16 @@ impl MainHandler {
10701077
return Ok(Response::with(status::NotModified));
10711078
}
10721079
};
1073-
let cache = vec![CacheDirective::Public, CacheDirective::MaxAge(SECONDS)];
1080+
let cache = if self.must_revalidate {
1081+
vec![
1082+
CacheDirective::Private,
1083+
CacheDirective::MustRevalidate,
1084+
CacheDirective::MaxAge(SECONDS)
1085+
]
1086+
} else {
1087+
vec![CacheDirective::Public, CacheDirective::MaxAge(SECONDS)]
1088+
};
1089+
//let cache = vec![CacheDirective::Public, CacheDirective::MaxAge(SECONDS)];
10741090
resp.headers.set(CacheControl(cache));
10751091
resp.headers.set(LastModified(HttpDate(time::at(modified))));
10761092
resp.headers.set(ETag(etag));

0 commit comments

Comments
 (0)