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