~athorp96/Coil

461b2f8a04a872d412bba1a5767ce63a90829db9 — Andrew Thorp 2 years ago 609955b
Only print 'text/*' mime types to to terminal
1 files changed, 5 insertions(+), 11 deletions(-)

M src/response.rs
M src/response.rs => src/response.rs +5 -11
@@ 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)
    }
}