diff --git a/Cargo.toml b/Cargo.toml index 19cc936..1645e9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ openssl = { version = "0.10.66", optional = true } rustls = { version = "0.23.13", optional = true } serde_yml = "0.0.12" log = "0.4.22" -pretty_env_logger = "0.5.0" +colog = "1.3.0" threadpool = "1.8.1" [features] diff --git a/src/flowgate/config.rs b/src/flowgate/config.rs index ead9846..0bc1716 100644 --- a/src/flowgate/config.rs +++ b/src/flowgate/config.rs @@ -26,13 +26,8 @@ pub struct Config { impl Config { pub fn parse(filename: &str) -> Option { - let Ok(file_content) = fs::read_to_string(filename) else { - return None; - }; - let Ok(docs) = serde_yml::from_str::(file_content.as_str()) else { - return None; - }; - let doc = docs.get(0)?; + let file_content = fs::read_to_string(filename).ok()?; + let doc = serde_yml::from_str::(file_content.as_str()).ok()?; let http_host = doc["http_host"].as_str()?.to_string(); let https_host = doc["https_host"].as_str()?.to_string(); diff --git a/src/flowgate/server.rs b/src/flowgate/server.rs index 5c09c4f..77cdae0 100644 --- a/src/flowgate/server.rs +++ b/src/flowgate/server.rs @@ -1,6 +1,6 @@ use std::{io::{Read, Write}, net::{Shutdown, SocketAddr, TcpListener}, sync::Arc, thread, time::Duration}; -use log::info; +use log::{debug, info}; use openssl::ssl::{NameType, SniError, SslAcceptor, SslAlert, SslMethod, SslRef}; use threadpool::ThreadPool; @@ -58,7 +58,7 @@ impl FlowgateServer { config, &mut stream, addr, - true + false ); } }); @@ -132,7 +132,7 @@ impl FlowgateServer { let reqst = String::from_utf8(reqst_data).ok()?; let reqst = reqst.trim_matches(char::from(0)); - let (head, _) = reqst.split_once("\r\n\r\n")?; + let (head, body) = reqst.split_once("\r\n\r\n")?; let mut head_lines = head.split("\r\n"); @@ -141,6 +141,7 @@ impl FlowgateServer { let mut host: &str = "honk"; let mut keep_alive: bool = false; + let mut content_length: usize = 0; for l in head_lines { let (key, value) = l.split_once(": ")?; @@ -152,6 +153,9 @@ impl FlowgateServer { if key == "connection" { keep_alive = value == "keep-alive"; } + if key == "content_length" { + content_length = value.parse().ok()?; + } } let site = config.get_site(host); @@ -165,9 +169,11 @@ impl FlowgateServer { site_stream.write((addr.to_string() + "\n" + reqst).as_bytes()).ok()?; - let mut body_data: Vec = Vec::new(); - stream.read_to_end(&mut body_data).ok()?; - site_stream.write_all(&body_data).ok()?; + if content_length != 0 && content_length > body.len() { + let mut body_data: Vec = Vec::new(); + stream.read_to_end(&mut body_data).ok()?; + site_stream.write_all(&body_data).ok()?; + } loop { let mut buf: Vec = Vec::new(); diff --git a/src/main.rs b/src/main.rs index 2671c85..9d6775f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,12 @@ mod flowgate; use flowgate::{Config, FlowgateServer}; fn main() { - pretty_env_logger::init(); + colog::init(); let config = Config::parse("conf.yml").unwrap(); let server = FlowgateServer::new(config); server.start(); + + loop {} }