net: Simplify content_type setter.

This commit is contained in:
Emilio Cobos Álvarez 2016-12-25 17:26:03 +01:00
parent 755697d6bb
commit d33ee4594d
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -438,24 +438,17 @@ impl Metadata {
/// Extract the parts of a Mime that we care about. /// Extract the parts of a Mime that we care about.
pub fn set_content_type(&mut self, content_type: Option<&Mime>) { pub fn set_content_type(&mut self, content_type: Option<&Mime>) {
match self.headers { if self.headers.is_none() {
None => self.headers = Some(Serde(Headers::new())), self.headers = Some(Serde(Headers::new()));
Some(_) => (),
} }
match content_type { if let Some(mime) = content_type {
None => (), self.headers.as_mut().unwrap().set(ContentType(mime.clone()));
Some(mime) => { self.content_type = Some(Serde(ContentType(mime.clone())));
if let Some(headers) = self.headers.as_mut() { let Mime(_, _, ref parameters) = *mime;
headers.set(ContentType(mime.clone())); for &(ref k, ref v) in parameters {
} if Attr::Charset == *k {
self.charset = Some(v.to_string());
self.content_type = Some(Serde(ContentType(mime.clone())));
let &Mime(_, _, ref parameters) = mime;
for &(ref k, ref v) in parameters {
if &Attr::Charset == k {
self.charset = Some(v.to_string());
}
} }
} }
} }