http compressions stage 1 attempt 2

This commit is contained in:
YK 2024-05-11 04:29:06 +03:00
parent ef899b461e
commit 35001306fb

View File

@ -69,10 +69,10 @@ async fn process (mut stream: TcpStream, args: A) -> Result<()> {
let mut data = data.into_inner();
let headers = Headers::parse(&mut data).await;
let encoding = Encoding::from(headers.get("Accept-Encoding"));
println!("{:?}", headers);
println!("{:?}", encoding);
use Method as M;
let response = match (method, target.as_str()) {
@ -103,6 +103,8 @@ async fn process (mut stream: TcpStream, args: A) -> Result<()> {
_ => Response::_404,
};
println!("{:?}", String::from_utf8_lossy(&response.clone().build()));
let _ = stream.write_all(&response.build()).await;
let _ = stream.flush().await;
@ -239,9 +241,9 @@ impl Response {
fn headers (&self) -> Vec<String> {
match self {
Self::TextPlain(text, enc) => vec![
enc.header().to_string(),
f!("Content-Type: text/plain"),
format!("Content-Length: {}", text.len())
format!("Content-Length: {}", text.len()),
enc.header().to_string(),
],
Self::OctetStream(bytes) => vec![
f!("Content-Type: application/octet-stream"),