From 63b615249443b8f897018f21473c2f1f8e43663c Mon Sep 17 00:00:00 2001 From: Andre Silva Date: Fri, 17 Jun 2016 01:51:34 +0100 Subject: [PATCH] fix(headers): Remove raw part when getting mutable reference to typed header If you get a mutable reference to a typed header it is possible to make the two representations be out of sync. To avoid this, after parsing the raw part it should be removed. Fixes #821. --- src/header/internals/item.rs | 3 +++ src/header/mod.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/header/internals/item.rs b/src/header/internals/item.rs index 5b1eff92a6..60c6972325 100644 --- a/src/header/internals/item.rs +++ b/src/header/internals/item.rs @@ -78,6 +78,9 @@ impl Item { Err(_) => () } } + if self.raw.is_some() && self.typed.get_mut(tid).is_some() { + self.raw = OptCell::new(None); + } self.typed.get_mut(tid).map(|typed| unsafe { typed.downcast_mut_unchecked() }) } } diff --git a/src/header/mod.rs b/src/header/mod.rs index 53499f80f1..661c45a82d 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -639,6 +639,7 @@ mod tests { fn test_get_mutable() { let mut headers = Headers::from_raw(&raw!(b"Content-Length: 10")).unwrap(); *headers.get_mut::().unwrap() = ContentLength(20); + assert_eq!(headers.get_raw("content-length").unwrap(), &[b"20".to_vec()][..]); assert_eq!(*headers.get::().unwrap(), ContentLength(20)); }