From 38ded8a8c37472ba43eee00721be3f457b56591c Mon Sep 17 00:00:00 2001 From: YK Date: Sat, 11 May 2024 04:31:48 +0300 Subject: [PATCH] http compressions stage 1 attempt 3 --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 19fc6f2..d9441c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -240,11 +240,18 @@ impl Response { fn headers (&self) -> Vec { match self { - Self::TextPlain(text, enc) => vec![ - f!("Content-Type: text/plain"), - format!("Content-Length: {}", text.len()), - enc.header().to_string(), - ], + Self::TextPlain(text, enc) => { + let mut v = vec![ + f!("Content-Type: text/plain"), + format!("Content-Length: {}", text.len()), + ]; + + let enc = enc.header(); + + if !enc.is_empty() { v.push(enc.to_string()) } + + v + }, Self::OctetStream(bytes) => vec![ f!("Content-Type: application/octet-stream"), format!("Content-Length: {}", bytes.len())