small fix
This commit is contained in:
parent
eb1fc68fa8
commit
0806ce7f58
@ -8,7 +8,7 @@ openssl = { version = "0.10.66", optional = true }
|
|||||||
rustls = { version = "0.23.13", optional = true }
|
rustls = { version = "0.23.13", optional = true }
|
||||||
serde_yml = "0.0.12"
|
serde_yml = "0.0.12"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
pretty_env_logger = "0.5.0"
|
colog = "1.3.0"
|
||||||
threadpool = "1.8.1"
|
threadpool = "1.8.1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -26,13 +26,8 @@ pub struct Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn parse(filename: &str) -> Option<Config> {
|
pub fn parse(filename: &str) -> Option<Config> {
|
||||||
let Ok(file_content) = fs::read_to_string(filename) else {
|
let file_content = fs::read_to_string(filename).ok()?;
|
||||||
return None;
|
let doc = serde_yml::from_str::<Value>(file_content.as_str()).ok()?;
|
||||||
};
|
|
||||||
let Ok(docs) = serde_yml::from_str::<Value>(file_content.as_str()) else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
let doc = docs.get(0)?;
|
|
||||||
|
|
||||||
let http_host = doc["http_host"].as_str()?.to_string();
|
let http_host = doc["http_host"].as_str()?.to_string();
|
||||||
let https_host = doc["https_host"].as_str()?.to_string();
|
let https_host = doc["https_host"].as_str()?.to_string();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{io::{Read, Write}, net::{Shutdown, SocketAddr, TcpListener}, sync::Arc, thread, time::Duration};
|
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 openssl::ssl::{NameType, SniError, SslAcceptor, SslAlert, SslMethod, SslRef};
|
||||||
use threadpool::ThreadPool;
|
use threadpool::ThreadPool;
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ impl FlowgateServer {
|
|||||||
config,
|
config,
|
||||||
&mut stream,
|
&mut stream,
|
||||||
addr,
|
addr,
|
||||||
true
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -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, _) = 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");
|
let mut head_lines = head.split("\r\n");
|
||||||
|
|
||||||
@ -141,6 +141,7 @@ impl FlowgateServer {
|
|||||||
|
|
||||||
let mut host: &str = "honk";
|
let mut host: &str = "honk";
|
||||||
let mut keep_alive: bool = false;
|
let mut keep_alive: bool = false;
|
||||||
|
let mut content_length: usize = 0;
|
||||||
|
|
||||||
for l in head_lines {
|
for l in head_lines {
|
||||||
let (key, value) = l.split_once(": ")?;
|
let (key, value) = l.split_once(": ")?;
|
||||||
@ -152,6 +153,9 @@ impl FlowgateServer {
|
|||||||
if key == "connection" {
|
if key == "connection" {
|
||||||
keep_alive = value == "keep-alive";
|
keep_alive = value == "keep-alive";
|
||||||
}
|
}
|
||||||
|
if key == "content_length" {
|
||||||
|
content_length = value.parse().ok()?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let site = config.get_site(host);
|
let site = config.get_site(host);
|
||||||
@ -165,9 +169,11 @@ 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 mut body_data: Vec<u8> = Vec::new();
|
if content_length != 0 && content_length > body.len() {
|
||||||
stream.read_to_end(&mut body_data).ok()?;
|
let mut body_data: Vec<u8> = Vec::new();
|
||||||
site_stream.write_all(&body_data).ok()?;
|
stream.read_to_end(&mut 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();
|
||||||
|
@ -3,10 +3,12 @@ mod flowgate;
|
|||||||
use flowgate::{Config, FlowgateServer};
|
use flowgate::{Config, FlowgateServer};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
pretty_env_logger::init();
|
colog::init();
|
||||||
|
|
||||||
let config = Config::parse("conf.yml").unwrap();
|
let config = Config::parse("conf.yml").unwrap();
|
||||||
let server = FlowgateServer::new(config);
|
let server = FlowgateServer::new(config);
|
||||||
|
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
|
loop {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user