Skip to content

Commit 0297147

Browse files
committed
feat(headers): add LastModified header
1 parent e255f88 commit 0297147

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/header/common/last_modified.rs

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 `LastModified` header field.
8+
#[deriving(PartialEq, Clone)]
9+
pub struct LastModified(pub Tm);
10+
11+
deref!(LastModified -> Tm)
12+
13+
impl Header for LastModified {
14+
fn header_name(_: Option<LastModified>) -> &'static str {
15+
"Last-Modified"
16+
}
17+
18+
fn parse_header(raw: &[Vec<u8>]) -> Option<LastModified> {
19+
from_one_raw_str(raw)
20+
}
21+
}
22+
23+
24+
impl HeaderFormat for LastModified {
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 LastModified {
35+
fn from_str(s: &str) -> Option<LastModified> {
36+
tm_from_str(s).map(LastModified)
37+
}
38+
}
39+
40+
bench_header!(imf_fixdate, LastModified, { vec![b"Sun, 07 Nov 1994 08:48:37 GMT".to_vec()] })
41+
bench_header!(rfc_850, LastModified, { vec![b"Sunday, 06-Nov-94 08:49:37 GMT".to_vec()] })
42+
bench_header!(asctime, LastModified, { vec![b"Sun Nov 6 08:49:37 1994".to_vec()] })

src/header/common/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ pub use self::connection::Connection;
1313
pub use self::content_length::ContentLength;
1414
pub use self::content_type::ContentType;
1515
pub use self::date::Date;
16+
pub use self::expires::Expires;
1617
pub use self::host::Host;
18+
pub use self::last_modified::LastModified;
1719
pub use self::location::Location;
1820
pub use self::transfer_encoding::TransferEncoding;
1921
pub use self::upgrade::Upgrade;
@@ -102,6 +104,9 @@ pub mod expires;
102104
/// Exposes the Host header.
103105
pub mod host;
104106

107+
/// Exposes the LastModified header.
108+
pub mod last_modified;
109+
105110
/// Exposes the Location header.
106111
pub mod location;
107112

0 commit comments

Comments
 (0)