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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user