From 3a59b3779c9a79b06507af271c53f8468e91acc9 Mon Sep 17 00:00:00 2001 From: dvkt Date: Sat, 4 Jan 2020 16:22:11 -0800 Subject: [PATCH] more logging statements --- src/server.rs | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/server.rs b/src/server.rs index a7a13ac..ab62d4c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -64,7 +64,7 @@ fn accept(stream: TcpStream, mut req: Request) -> Result<()> { let mut lines = reader.lines(); if let Some(Ok(line)) = lines.next() { println!( - "{}│{} Client sent: {}{:?}{}", + "{}│{} Client sent:\t{}{:?}{}", color::Green, color::Reset, color::Cyan, @@ -191,6 +191,15 @@ where } menu.end()?; + println!( + "{}│{} Server reply:\t{}DIR {}{}{}", + color::Green, + color::Reset, + color::Yellow, + color::Bold, + req.relative_file_path(), + color::Reset, + ); Ok(()) } @@ -199,8 +208,18 @@ fn write_file<'a, W>(mut w: &'a W, req: Request) -> Result<()> where &'a W: Write, { - let mut f = fs::File::open(&req.file_path())?; + let path = req.file_path(); + let mut f = fs::File::open(&path)?; io::copy(&mut f, &mut w)?; + println!( + "{}│{} Server reply:\t{}FILE {}{}{}", + color::Green, + color::Reset, + color::Yellow, + color::Bold, + req.relative_file_path(), + color::Reset, + ); Ok(()) } @@ -215,7 +234,7 @@ where let reader = if is_executable(&path) { shell(&path, &[&req.query, &req.host, &req.port.to_string()])? } else { - fs::read_to_string(path)? + fs::read_to_string(&path)? }; for line in reader.lines() { @@ -236,6 +255,15 @@ where line.push_str("\r\n"); w.write_all(line.as_bytes())?; } + println!( + "{}│{} Server reply:\t{}MAP {}{}{}", + color::Green, + color::Reset, + color::Yellow, + color::Bold, + req.relative_file_path(), + color::Reset, + ); Ok(()) } @@ -244,6 +272,13 @@ where &'a W: Write, { let line = format!("3Not Found: {}\t/\tnone\t70\r\n", req.selector); + println!( + "{}│ Not found: {}{}{}", + color::Red, + color::Cyan, + req.relative_file_path(), + color::Reset, + ); w.write_all(line.as_bytes())?; Ok(()) }