Support Date header
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 17:15:58 +0000 (17:15 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 17:15:58 +0000 (17:15 +0000)
src/codec.rs
src/parser.rs
src/types.rs

index 040e995e04b83fb885dcfe5107610b1b3b236b4b..c873c51a1fbb574777263937676c4a12bac52f7e 100644 (file)
@@ -435,7 +435,7 @@ mod tests {
                            purpose=icon\r\nContact:*\r\nContent-Disposition:\
                            session\r\nContent-Encoding:gzip\r\nContent-Language:\
                            en-gb\r\nContent-Length:0\r\nContent-Type:text/plain\r\nCSeq:1 \
-                           MESSAGE\r\nVia: localhost\r\n\r\n")
+                           MESSAGE\r\nDate:Sat, 13 Nov 2010 23:29:00 GMT\r\nVia: localhost\r\n\r\n")
         });
 
         let finished = request.and_then(|(socket, _request)| {
index e1fed22ca1e93af20269e74db7da8ce4b93089db..6adbb5ed51491da9fffb89d791869d39a471f913 100644 (file)
@@ -15,7 +15,8 @@ use types::{PathSegment, HostPort, Host, Hostname, UriParameter, UriHeader, UriH
             GenericParam, AcceptParam, AcceptRange, Coding, Encoding, LanguageTag, LanguageRange,
             Language, AlertParam, Qop, AuthenticationInfo, AuthParam, Algorithm, DigestResponse,
             Credentials, CallId, Purpose, InfoParam, Info, NameAddr, ContactParam, ContactTarget,
-            Contact, DispositionType, Handling, DispositionParam, ContentCoding};
+            Contact, DispositionType, Handling, DispositionParam, ContentCoding, Day, Month, Date,
+            Time, DateTime};
 
 fn is_mark(c: u8) -> bool {
     c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' ||
@@ -839,6 +840,48 @@ named!(cseq_header<(u32, Method)>, preceded!(
                tag!(" "),
                method)));
 
+named!(wkday<Day>, alt!(
+       tag!(b"Mon") => { |_| Day::Monday } |
+       tag!(b"Tue") => { |_| Day::Tuesday } |
+       tag!(b"Wed") => { |_| Day::Wednesday } |
+       tag!(b"Thu") => { |_| Day::Thursday } |
+       tag!(b"Fri") => { |_| Day::Friday } |
+       tag!(b"Sat") => { |_| Day::Saturday } |
+       tag!(b"Sun") => { |_| Day::Sunday }));
+
+named!(month<Month>, alt!(
+       tag!(b"Jan") => { |_| Month::January } |
+       tag!(b"Feb") => { |_| Month::February } |
+       tag!(b"Mar") => { |_| Month::March } |
+       tag!(b"Apr") => { |_| Month::April } |
+       tag!(b"May") => { |_| Month::May } |
+       tag!(b"Jun") => { |_| Month::June } |
+       tag!(b"Jul") => { |_| Month::July } |
+       tag!(b"Aug") => { |_| Month::August } |
+       tag!(b"Sep") => { |_| Month::September } |
+       tag!(b"Oct") => { |_| Month::October } |
+       tag!(b"Nov") => { |_| Month::November } |
+       tag!(b"Dec") => { |_| Month::December }));
+
+named!(date<Date>, tuple!(
+       terminated!(number, tag!(b" ")),
+       terminated!(month, tag!(b" ")),
+       number));
+
+named!(time<Time>, tuple!(
+       terminated!(number, tag!(b":")),
+       terminated!(number, tag!(b":")),
+       number));
+
+named!(date_time<DateTime>, tuple!(
+       terminated!(wkday, tag!(b", ")),
+       terminated!(date, tag!(b" ")),
+       terminated!(time, tag!(b" GMT"))));
+
+named!(date_header<DateTime>, preceded!(
+       tag!(b"Date:"),
+       date_time));
+
 named!(pub header<Header>, alt!(
 // RFC 3261 Headers
        accept_header => { |a| Header::Accept(a) } |
@@ -856,5 +899,6 @@ named!(pub header<Header>, alt!(
        content_language_header => { |l| Header::ContentLanguage(l) } |
        content_length_header => { |l| Header::ContentLength(l) } |
        content_type_header => { |t| Header::ContentType(t) } |
-       cseq_header => { |(c, m)| Header::CSeq(c, m) }
+       cseq_header => { |(c, m)| Header::CSeq(c, m) } |
+       date_header => { |d| Header::Date(d) }
 ));
index 93a3382653be8576ae5ccb0347598476cc822a9b..3276ed27c37c9264f71be4be3e58cd985b657e3e 100644 (file)
@@ -298,6 +298,39 @@ pub enum DispositionParam {
 
 pub type ContentCoding = Vec<u8>;
 
+#[derive(Debug)]
+pub enum Day {
+    Monday,
+    Tuesday,
+    Wednesday,
+    Thursday,
+    Friday,
+    Saturday,
+    Sunday,
+}
+
+#[derive(Debug)]
+pub enum Month {
+    January,
+    February,
+    March,
+    April,
+    May,
+    June,
+    July,
+    August,
+    September,
+    October,
+    November,
+    December,
+}
+
+pub type Date = (u8, Month, u16);
+
+pub type Time = (u8, u8, u8);
+
+pub type DateTime = (Day, Date, Time);
+
 #[derive(Debug)]
 pub enum Header {
     Accept(Vec<AcceptRange>),
@@ -316,6 +349,7 @@ pub enum Header {
     ContentLength(u32),
     ContentType(MediaType),
     CSeq(u32, Method),
+    Date(DateTime),
     From(Uri),
     To(Uri),
     Extension { name: String, value: String },