http compressions stage 1 attempt 2
This commit is contained in:
parent
ef899b461e
commit
35001306fb
10
src/main.rs
10
src/main.rs
@ -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"),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user