Add get_mut for modifying the typed representation of Headers.

Also adds an associated test and updates code to use it instead
of cloning and setting when possible.
This commit is contained in:
Jonathan Reem
2014-09-20 05:52:41 -07:00
parent 858a09304a
commit d3a62fa0d5
3 changed files with 65 additions and 27 deletions

View File

@@ -121,16 +121,19 @@ impl Request<Fresh> {
// cant do in match above, thanks borrowck
if chunked {
//TODO: use CollectionViews (when implemented) to prevent double hash/lookup
let encodings = match self.headers.get::<common::TransferEncoding>().map(|h| h.clone()) {
Some(common::TransferEncoding(mut encodings)) => {
let encodings = match self.headers.get_mut::<common::TransferEncoding>() {
Some(&common::TransferEncoding(ref mut encodings)) => {
//TODO: check if chunked is already in encodings. use HashSet?
encodings.push(common::transfer_encoding::Chunked);
encodings
false
},
None => vec![common::transfer_encoding::Chunked]
None => true
};
self.headers.set(common::TransferEncoding(encodings));
if encodings {
self.headers.set::<common::TransferEncoding>(
common::TransferEncoding(vec![common::transfer_encoding::Chunked]))
}
}
for (name, header) in self.headers.iter() {