From 461b2f8a04a872d412bba1a5767ce63a90829db9 Mon Sep 17 00:00:00 2001 From: Andrew Thorp Date: Mon, 26 Jul 2021 00:51:34 -0400 Subject: [PATCH] Only print 'text/*' mime types to to terminal --- src/response.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/response.rs b/src/response.rs index 2529710..ea4e89d 100644 --- a/src/response.rs +++ b/src/response.rs @@ -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) } } -- 2.45.2