small fix

This commit is contained in:
MeexReay 2024-09-13 22:32:51 +03:00
parent eb1fc68fa8
commit 0806ce7f58
4 changed files with 18 additions and 15 deletions

View File

@ -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]

View File

@ -26,13 +26,8 @@ pub struct Config {
impl Config {
pub fn parse(filename: &str) -> Option<Config> {
let Ok(file_content) = fs::read_to_string(filename) else {
return None;
};
let Ok(docs) = serde_yml::from_str::<Value>(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::<Value>(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();

View File

@ -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()?;
if content_length != 0 && content_length > body.len() {
let mut body_data: Vec<u8> = Vec::new();
stream.read_to_end(&mut body_data).ok()?;
site_stream.write_all(&body_data).ok()?;
}
loop {
let mut buf: Vec<u8> = Vec::new();

View File

@ -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 {}
}