Doesn't really work, but I'm starting to implement request headers

This commit is contained in:
2025-11-29 11:46:45 +00:00
parent 0ee35b2795
commit 0cfad78526
2 changed files with 13 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ use crate::
ROOT_DIR, ROOT_DIR,
}; };
pub fn watch_files(file_list: &Vec<PathBuf>) -> u8 pub fn watch_files(file_list: &[PathBuf]) -> u8
{ {
let (tx, rx) = mpsc::channel::<Result<Event>>(); // Use recommended_watcher() to automatically select the best implementation let (tx, rx) = mpsc::channel::<Result<Event>>(); // Use recommended_watcher() to automatically select the best implementation

View File

@@ -20,7 +20,6 @@ lazy_static! {
// TODO, make 'code' an enum // TODO, make 'code' an enum
// TODO, safely modify bytes in thread. // TODO, safely modify bytes in thread.
// TODO, Makes paths more consistent. // TODO, Makes paths more consistent.
// TODO, Avoid copying bytes
fn main() -> io::Result<()> fn main() -> io::Result<()>
{ {
#![warn(clippy::pedantic, clippy::perf)] #![warn(clippy::pedantic, clippy::perf)]
@@ -32,11 +31,6 @@ fn main() -> io::Result<()>
let listener = TcpListener::bind(BIND_ADDRESS).unwrap(); let listener = TcpListener::bind(BIND_ADDRESS).unwrap();
println!("Listening at {BIND_ADDRESS}"); println!("Listening at {BIND_ADDRESS}");
/*
let mut file_list: Vec<std::path::PathBuf> = vec![ROOT_DIR.join(INDEX_FILE)];
let (mut bytes, mut new_file_list) = files::read_file(INDEX_FILE, 0);
file_list.append(&mut new_file_list);
*/
// File watch thread // File watch thread
thread::spawn( thread::spawn(
move || { move || {
@@ -44,7 +38,6 @@ fn main() -> io::Result<()>
let mut file_list: Vec<PathBuf>; let mut file_list: Vec<PathBuf>;
(bytes, file_list) = files::read_file(INDEX_FILE, 0); (bytes, file_list) = files::read_file(INDEX_FILE, 0);
file_list.push(ROOT_DIR.join(INDEX_FILE)); file_list.push(ROOT_DIR.join(INDEX_FILE));
println!("Tracking: {:?}", file_list);
tx.send(bytes.clone()).unwrap(); tx.send(bytes.clone()).unwrap();
loop loop
@@ -56,7 +49,7 @@ fn main() -> io::Result<()>
(bytes, file_list) = files::read_file(INDEX_FILE, 0); (bytes, file_list) = files::read_file(INDEX_FILE, 0);
file_list.push(ROOT_DIR.join(INDEX_FILE)); file_list.push(ROOT_DIR.join(INDEX_FILE));
tx.send(bytes.clone()).unwrap(); tx.send(bytes).unwrap();
} }
} }
} }
@@ -71,9 +64,17 @@ fn main() -> io::Result<()>
Ok(()) Ok(())
} }
fn handle_connection(mut stream: TcpStream, bytes: &Vec<u8>) fn handle_connection(mut stream: TcpStream, bytes: &[u8])
{ {
let buf_reader = BufReader::new(&stream); let buf_reader = BufReader::new(&stream);
println!("CONNECTION: {buf_reader:#?}"); let notp_request: Vec<_> = buf_reader
stream.write_all(bytes.as_slice()).unwrap(); .lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();
println!("REQUEST: {:?}", notp_request);
if let Err(e) = stream.write_all(bytes)
{
eprintln!("Failed to send response: {}", e);
}
} }