content length in request remove

This commit is contained in:
MeexReay 2024-09-13 22:04:13 +03:00
parent 662dd364c1
commit eb1fc68fa8

View File

@ -132,7 +132,7 @@ impl FlowgateServer {
let reqst = String::from_utf8(reqst_data).ok()?; let reqst = String::from_utf8(reqst_data).ok()?;
let reqst = reqst.trim_matches(char::from(0)); let reqst = reqst.trim_matches(char::from(0));
let (head, body) = reqst.split_once("\r\n\r\n")?; let (head, _) = reqst.split_once("\r\n\r\n")?;
let mut head_lines = head.split("\r\n"); let mut head_lines = head.split("\r\n");
@ -140,7 +140,7 @@ impl FlowgateServer {
let status: Vec<&str> = status.split(" ").collect(); let status: Vec<&str> = status.split(" ").collect();
let mut host: &str = "honk"; let mut host: &str = "honk";
let mut content_length: usize = 0; let mut keep_alive: bool = false;
for l in head_lines { for l in head_lines {
let (key, value) = l.split_once(": ")?; let (key, value) = l.split_once(": ")?;
@ -149,8 +149,8 @@ impl FlowgateServer {
if key == "host" { if key == "host" {
host = &value; host = &value;
} }
if key == "content_length" { if key == "connection" {
content_length = value.parse().ok()?; keep_alive = value == "keep-alive";
} }
} }
@ -165,12 +165,9 @@ impl FlowgateServer {
site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?; site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?;
let body_len = body.len(); let mut body_data: Vec<u8> = Vec::new();
if body_len < content_length { stream.read_to_end(&mut body_data).ok()?;
let mut body_data: Vec<u8> = vec![0; content_length - body_len];
stream.read_exact(&mut body_data).ok()?;
site_stream.write_all(&body_data).ok()?; site_stream.write_all(&body_data).ok()?;
}
loop { loop {
let mut buf: Vec<u8> = Vec::new(); let mut buf: Vec<u8> = Vec::new();
@ -184,14 +181,14 @@ impl FlowgateServer {
let method = status[0]; let method = status[0];
let page = status[1]; let page = status[1];
site_stream.shutdown(Shutdown::Both).ok()?;
if https { if https {
info!("{} > {} https://{}{}", addr.to_string(), method, host, page); info!("{} > {} https://{}{}", addr.to_string(), method, host, page);
} else { } else {
info!("{} > {} http://{}{}", addr.to_string(), method, host, page); info!("{} > {} http://{}{}", addr.to_string(), method, host, page);
} }
site_stream.shutdown(Shutdown::Both).ok()?;
Some(()) Some(())
} }
} }