Skip to content

Commit

Permalink
fix(headers): Remove raw part when getting mutable reference to typed…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
andresilva authored and seanmonstar committed Jun 21, 2016
1 parent f49912a commit 63b6152
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/header/internals/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
}
}
Expand Down
1 change: 1 addition & 0 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<ContentLength>().unwrap() = ContentLength(20);
assert_eq!(headers.get_raw("content-length").unwrap(), &[b"20".to_vec()][..]);
assert_eq!(*headers.get::<ContentLength>().unwrap(), ContentLength(20));
}

Expand Down

0 comments on commit 63b6152

Please sign in to comment.