@@ 175,17 175,11 @@ impl Response {
impl fmt::Display for Response {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- let body_string = match &self.body {
- Some(v) => {
- if let Ok(s) = String::from_utf8(v.to_vec()) {
- s
- } else {
- String::new()
- }
- }
-
- None => String::new(),
- };
+ let mut body_string = String::new();
+ if self.header.meta.starts_with("text/") {
+ body_string = String::from_utf8(self.body.clone().unwrap().to_vec())
+ .expect("mime type is text but body could not be parsed as UTF-8");
+ }
write!(f, "{}\n{}", self.header, body_string)
}
}