|
| 1 | +use std::fmt; |
| 2 | +use std::str::FromStr; |
| 3 | +use time::Tm; |
| 4 | +use header::{Header, HeaderFormat}; |
| 5 | +use header::parsing::from_one_raw_str; |
| 6 | +use header::parsing::tm_from_str; |
| 7 | + |
| 8 | +/// The `If-Unmodified-Since` header field. |
| 9 | +#[derive(Copy, PartialEq, Clone, Debug)] |
| 10 | +pub struct IfUnmodifiedSince(pub Tm); |
| 11 | + |
| 12 | +deref!(IfUnmodifiedSince => Tm); |
| 13 | + |
| 14 | +impl Header for IfUnmodifiedSince { |
| 15 | + fn header_name() -> &'static str { |
| 16 | + "If-Unmodified-Since" |
| 17 | + } |
| 18 | + |
| 19 | + fn parse_header(raw: &[Vec<u8>]) -> Option<IfUnmodifiedSince> { |
| 20 | + from_one_raw_str(raw) |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +impl HeaderFormat for IfUnmodifiedSince { |
| 26 | + fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
| 27 | + let tm = self.0; |
| 28 | + let tm = match tm.tm_utcoff { |
| 29 | + 0 => tm, |
| 30 | + _ => tm.to_utc(), |
| 31 | + }; |
| 32 | + fmt::Display::fmt(&tm.rfc822(), fmt) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +impl FromStr for IfUnmodifiedSince { |
| 37 | + type Err = (); |
| 38 | + fn from_str(s: &str) -> Result<IfUnmodifiedSince, ()> { |
| 39 | + tm_from_str(s).map(IfUnmodifiedSince).ok_or(()) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +bench_header!(imf_fixdate, IfUnmodifiedSince, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] }); |
| 44 | +bench_header!(rfc_850, IfUnmodifiedSince, { vec![b"Sunday, 06-Nov-94 08:49:37 GMT".to_vec()] }); |
| 45 | +bench_header!(asctime, IfUnmodifiedSince, { vec![b"Sun Nov 6 08:49:37 1994".to_vec()] }); |
0 commit comments