@@ -59,6 +59,7 @@ impl Flags {
5959 const PRIVATE : Self = Self { bits : 0b001000000 } ;
6060 const PROXY_REVALIDATE : Self = Self { bits : 0b010000000 } ;
6161 const IMMUTABLE : Self = Self { bits : 0b100000000 } ;
62+ const MUST_UNDERSTAND : Self = Self { bits : 0b1000000000 } ;
6263
6364 fn empty ( ) -> Self {
6465 Self { bits : 0 }
@@ -121,6 +122,10 @@ impl CacheControl {
121122 pub fn immutable ( & self ) -> bool {
122123 self . flags . contains ( Flags :: IMMUTABLE )
123124 }
125+ /// Check if the `must_understand` directive is set.
126+ pub fn must_understand ( & self ) -> bool {
127+ self . flags . contains ( Flags :: MUST_UNDERSTAND )
128+ }
124129
125130 /// Get the value of the `max-age` directive if set.
126131 pub fn max_age ( & self ) -> Option < Duration > {
@@ -186,6 +191,11 @@ impl CacheControl {
186191 self
187192 }
188193
194+ /// Set the `must_understand` directive.
195+ pub fn with_must_understand ( mut self ) -> Self {
196+ self . flags . insert ( Flags :: MUST_UNDERSTAND ) ;
197+ self
198+ }
189199 /// Set the `max-age` directive.
190200 pub fn with_max_age ( mut self , duration : Duration ) -> Self {
191201 self . max_age = Some ( duration. into ( ) ) ;
@@ -258,6 +268,9 @@ impl FromIterator<KnownDirective> for FromIter {
258268 Directive :: MustRevalidate => {
259269 cc. flags . insert ( Flags :: MUST_REVALIDATE ) ;
260270 }
271+ Directive :: MustUnderstand => {
272+ cc. flags . insert ( Flags :: MUST_UNDERSTAND ) ;
273+ }
261274 Directive :: Public => {
262275 cc. flags . insert ( Flags :: PUBLIC ) ;
263276 }
@@ -310,6 +323,7 @@ impl<'a> fmt::Display for Fmt<'a> {
310323 if_flag ( Flags :: PUBLIC , Directive :: Public ) ,
311324 if_flag ( Flags :: PRIVATE , Directive :: Private ) ,
312325 if_flag ( Flags :: IMMUTABLE , Directive :: Immutable ) ,
326+ if_flag ( Flags :: MUST_UNDERSTAND , Directive :: MustUnderstand ) ,
313327 if_flag ( Flags :: PROXY_REVALIDATE , Directive :: ProxyRevalidate ) ,
314328 self . 0
315329 . max_age
@@ -355,6 +369,7 @@ enum Directive {
355369
356370 // response directives
357371 MustRevalidate ,
372+ MustUnderstand ,
358373 Public ,
359374 Private ,
360375 Immutable ,
@@ -376,6 +391,7 @@ impl fmt::Display for Directive {
376391 Directive :: MinFresh ( secs) => return write ! ( f, "min-fresh={}" , secs) ,
377392
378393 Directive :: MustRevalidate => "must-revalidate" ,
394+ Directive :: MustUnderstand => "must-understand" ,
379395 Directive :: Public => "public" ,
380396 Directive :: Private => "private" ,
381397 Directive :: Immutable => "immutable" ,
@@ -399,6 +415,7 @@ impl FromStr for KnownDirective {
399415 "public" => Directive :: Public ,
400416 "private" => Directive :: Private ,
401417 "immutable" => Directive :: Immutable ,
418+ "must-understand" => Directive :: MustUnderstand ,
402419 "proxy-revalidate" => Directive :: ProxyRevalidate ,
403420 "" => return Err ( ( ) ) ,
404421 _ => match s. find ( '=' ) {
@@ -472,6 +489,18 @@ mod tests {
472489 assert ! ( cc. immutable( ) ) ;
473490 }
474491
492+ #[ test]
493+ fn test_must_understand ( ) {
494+ let cc = CacheControl :: new ( ) . with_must_understand ( ) ;
495+ let headers = test_encode ( cc. clone ( ) ) ;
496+ assert_eq ! ( headers[ "cache-control" ] , "must-understand" ) ;
497+ assert_eq ! (
498+ test_decode:: <CacheControl >( & [ "must-understand" ] ) . unwrap( ) ,
499+ cc
500+ ) ;
501+ assert ! ( cc. must_understand( ) ) ;
502+ }
503+
475504 #[ test]
476505 fn test_parse_bad_syntax ( ) {
477506 assert_eq ! ( test_decode:: <CacheControl >( & [ "max-age=lolz" ] ) , None ) ;
0 commit comments