Skip to content

Commit e9af13c

Browse files
committed
Merge pull request #297 from hugoduncan/feature/add-if-unmodified-since
feat(headers): add IfUnmodifiedSince header
2 parents 04e865c + b5543b6 commit e9af13c

File tree

2 files changed

+47
-0
lines changed

2 files changed

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

src/header/common/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use self::etag::Etag;
2121
pub use self::expires::Expires;
2222
pub use self::host::Host;
2323
pub use self::if_modified_since::IfModifiedSince;
24+
pub use self::if_unmodified_since::IfUnmodifiedSince;
2425
pub use self::last_modified::LastModified;
2526
pub use self::location::Location;
2627
pub use self::pragma::Pragma;
@@ -157,6 +158,7 @@ mod expires;
157158
mod host;
158159
mod last_modified;
159160
mod if_modified_since;
161+
mod if_unmodified_since;
160162
mod location;
161163
mod pragma;
162164
mod referer;

0 commit comments

Comments
 (0)