Skip to content

Commit 879d2d4

Browse files
allenapseanmonstar
authored andcommitted
Add methods for must-revalidate flag to CacheControl
1 parent 0fbde12 commit 879d2d4

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/common/cache_control.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ impl CacheControl {
123123
pub fn immutable(&self) -> bool {
124124
self.flags.contains(Flags::IMMUTABLE)
125125
}
126-
/// Check if the `must_understand` directive is set.
126+
127+
/// Check if the `must-revalidate` directive is set.
128+
pub fn must_revalidate(&self) -> bool {
129+
self.flags.contains(Flags::MUST_REVALIDATE)
130+
}
131+
132+
/// Check if the `must-understand` directive is set.
127133
pub fn must_understand(&self) -> bool {
128134
self.flags.contains(Flags::MUST_UNDERSTAND)
129135
}
@@ -192,11 +198,18 @@ impl CacheControl {
192198
self
193199
}
194200

195-
/// Set the `must_understand` directive.
201+
/// Set the `must-revalidate` directive.
202+
pub fn with_must_revalidate(mut self) -> Self {
203+
self.flags.insert(Flags::MUST_REVALIDATE);
204+
self
205+
}
206+
207+
/// Set the `must-understand` directive.
196208
pub fn with_must_understand(mut self) -> Self {
197209
self.flags.insert(Flags::MUST_UNDERSTAND);
198210
self
199211
}
212+
200213
/// Set the `max-age` directive.
201214
pub fn with_max_age(mut self, duration: Duration) -> Self {
202215
self.max_age = Some(duration.into());
@@ -490,6 +503,18 @@ mod tests {
490503
assert!(cc.immutable());
491504
}
492505

506+
#[test]
507+
fn test_must_revalidate() {
508+
let cc = CacheControl::new().with_must_revalidate();
509+
let headers = test_encode(cc.clone());
510+
assert_eq!(headers["cache-control"], "must-revalidate");
511+
assert_eq!(
512+
test_decode::<CacheControl>(&["must-revalidate"]).unwrap(),
513+
cc
514+
);
515+
assert!(cc.must_revalidate());
516+
}
517+
493518
#[test]
494519
fn test_must_understand() {
495520
let cc = CacheControl::new().with_must_understand();

0 commit comments

Comments
 (0)