Support Content-Disposition header
authorRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 15:32:28 +0000 (15:32 +0000)
committerRichard Whitehouse <github@richardwhiuk.com>
Sun, 29 Oct 2017 15:32:36 +0000 (15:32 +0000)
src/codec.rs
src/parser.rs
src/types.rs

index adce8bc968f7776ae0a38371828b2430b1a501b4..dedd02b1a7c453949a35556d4af5c0344a77ff2d 100644 (file)
@@ -432,7 +432,8 @@ mod tests {
                            MESSAGE\r\nAuthentication-Info:qop=auth\r\nAuthorization:Digest \
                            username=\"Alice\"\r\nCall-ID:f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.\
                            bar.com\r\nCall-Info:<http://wwww.example.com/alice/photo.jpg>;\
-                           purpose=icon\r\nContact:*\r\nVia: localhost\r\n\r\n")
+                           purpose=icon\r\nContact:*\r\nContent-Disposition:session\r\nVia: \
+                           localhost\r\n\r\n")
         });
 
         let finished = request.and_then(|(socket, _request)| {
index 1e77e48732796fe1aa98b8dd7b0e313ce47f51f9..643b98b1e572af1cfcb46e7be18bfe3b9be2ecd7 100644 (file)
@@ -14,7 +14,8 @@ use types::{PathSegment, HostPort, Host, Hostname, UriParameter, UriHeader, UriH
             Header, MediaType, MediaFullType, MediaParameter, MediaRange, GenericParam,
             AcceptParam, AcceptRange, Coding, Encoding, LanguageRange, Language, AlertParam, Qop,
             AuthenticationInfo, AuthParam, Algorithm, DigestResponse, Credentials, CallId,
-            Purpose, InfoParam, Info, NameAddr, ContactParam, ContactTarget, Contact};
+            Purpose, InfoParam, Info, NameAddr, ContactParam, ContactTarget, Contact,
+            DispositionType, Handling, DispositionParam};
 
 fn is_mark(c: u8) -> bool {
     c == b'-' || c == b'_' || c == b'.' || c == b'!' || c == b'~' || c == b'*' || c == b'\'' ||
@@ -784,6 +785,31 @@ named!(contact_header<Contact>, preceded!(
                        tag!(","),
                        contact_target) => { |c| Contact::Contact(c) })));
 
+named!(disp_type<DispositionType>, alt!(
+       tag!(b"render") => { |_| DispositionType::Render } |
+       tag!(b"session") => { |_| DispositionType::Session } |
+       tag!(b"icon") => { |_| DispositionType::Icon } |
+       tag!(b"alert") => { |_| DispositionType::Alert } |
+       token => { |t| DispositionType::Token(t) }
+));
+
+named!(handling<Handling>, alt!(
+       tag!(b"optional") => { |_| Handling::Optional } |
+       tag!(b"required") => { |_| Handling::Required } |
+       token => { |t| Handling::Token(t) }));
+
+named!(disp_param<DispositionParam>, alt!(
+       preceded!(tag!(b"handling="), handling) => { |h| DispositionParam::Handling(h) } |
+       generic_param => { |g| DispositionParam::Generic(g) }));
+
+named!(content_disposition_header<(DispositionType, Vec<DispositionParam>)>, preceded!(
+       tag!(b"Content-Disposition:"),
+       tuple!(
+               disp_type,
+               many0!(preceded!(
+                       tag!(b";"),
+                       disp_param)))));
+
 named!(pub header<Header>, alt!(
 // RFC 3261 Headers
        accept_header => { |a| Header::Accept(a) } |
@@ -795,5 +821,6 @@ named!(pub header<Header>, alt!(
        authorization_header => { |a| Header::Authorization(a) } |
        call_id_header => { |c| Header::CallId(c) } |
        call_info_header => { |c| Header::CallInfo(c) } |
-       contact_header => { |c| Header::Contact(c) }
+       contact_header => { |c| Header::Contact(c) } |
+       content_disposition_header => { |(t, p)| Header::ContentDisposition(t, p) }
 ));
index 22785281068538a85a6470c46a9dfd6243eca91a..177a037ee16d25241d108c79ad1b1c8c7780a6f7 100644 (file)
@@ -270,6 +270,28 @@ pub enum Contact {
     Contact(Vec<(ContactTarget, Vec<ContactParam>)>),
 }
 
+#[derive(Debug)]
+pub enum DispositionType {
+    Render,
+    Session,
+    Icon,
+    Alert,
+    Token(Vec<u8>),
+}
+
+#[derive(Debug)]
+pub enum Handling {
+    Optional,
+    Required,
+    Token(Vec<u8>),
+}
+
+#[derive(Debug)]
+pub enum DispositionParam {
+    Handling(Handling),
+    Generic(GenericParam),
+}
+
 #[derive(Debug)]
 pub enum Header {
     Accept(Vec<AcceptRange>),
@@ -282,6 +304,7 @@ pub enum Header {
     CallId(CallId),
     CallInfo(Vec<Info>),
     Contact(Contact),
+    ContentDisposition(DispositionType, Vec<DispositionParam>),
     From(Uri),
     To(Uri),
     Extension { name: String, value: String },