1 use HeaderValue; 2 3 /// The `Pragma` header defined by HTTP/1.0. 4 /// 5 /// > The "Pragma" header field allows backwards compatibility with 6 /// > HTTP/1.0 caches, so that clients can specify a "no-cache" request 7 /// > that they will understand (as Cache-Control was not defined until 8 /// > HTTP/1.1). When the Cache-Control header field is also present and 9 /// > understood in a request, Pragma is ignored. 10 /// > In HTTP/1.0, Pragma was defined as an extensible field for 11 /// > implementation-specified directives for recipients. This 12 /// > specification deprecates such extensions to improve interoperability. 13 /// 14 /// Spec: [https://tools.ietf.org/html/rfc7234#section-5.4][url] 15 /// 16 /// [url]: https://tools.ietf.org/html/rfc7234#section-5.4 17 /// 18 /// # Examples 19 /// 20 /// ``` 21 /// # extern crate headers; 22 /// use headers::Pragma; 23 /// 24 /// let pragma = Pragma::no_cache(); 25 /// ``` 26 #[derive(Clone, Debug, PartialEq)] 27 pub struct Pragma(HeaderValue); 28 29 derive_header! { 30 Pragma(_), 31 name: PRAGMA 32 } 33 34 impl Pragma { 35 /// Construct the literal `no-cache` Pragma header. no_cache() -> Pragma36 pub fn no_cache() -> Pragma { 37 Pragma(HeaderValue::from_static("no-cache")) 38 } 39 40 /// Return whether this pragma is `no-cache`. is_no_cache(&self) -> bool41 pub fn is_no_cache(&self) -> bool { 42 self.0 == "no-cache" 43 } 44 } 45 46 #[cfg(test)] 47 mod tests { 48 use super::super::test_decode; 49 use super::Pragma; 50 51 #[test] no_cache_is_no_cache()52 fn no_cache_is_no_cache() { 53 assert!(Pragma::no_cache().is_no_cache()); 54 } 55 56 #[test] etc_is_not_no_cache()57 fn etc_is_not_no_cache() { 58 let ext = test_decode::<Pragma>(&["dexter"]).unwrap(); 59 assert!(!ext.is_no_cache()); 60 } 61 } 62