Skip to content

Commit 0903340

Browse files
committed
Merge pull request #183 from cmr/if-modified-since
header: add If-Modified-Since support
2 parents 5b49076 + e2d387d commit 0903340

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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()] })

src/header/common/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ pub mod host;
102102
/// Exposes the LastModified header.
103103
pub mod last_modified;
104104

105+
/// Exposes the If-Modified-Since header.
106+
pub mod if_modified_since;
107+
105108
/// Exposes the Location header.
106109
pub mod location;
107110

0 commit comments

Comments
 (0)