diff --git a/Cargo.toml b/Cargo.toml index 0aedb29..67ca3fb 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,13 +26,13 @@ toml = "^0.3.2" serde_derive = "^0.9.14" serde = "^0.9.14" -stderr ="0.7.0" # 要和 poolite 所用的同一个版本,否则loger不能正常工作。 -poolite = "0.6.1" -app = "0.5.5" +stderr ="0.7.1" # 要和 poolite 所用的同一个版本,否则loger不能正常工作。 +poolite = "0.6.2" +app = "0.5.6" + # stderr = { git = "https://github.com/biluohc/stderr", branch = "master", version = "0.7.0"} # poolite = { git = "https://github.com/biluohc/poolite",branch = "master", version = "0.6.1" } # app = { git = "https://github.com/biluohc/app-rs", branch = "master", version = "0.5.5" } # stderr = { path = "../stderr" } # poolite = { path ="../poolite" } # app = { path = "../app" } - diff --git a/build.rs b/build.rs index e3327fc..0785ace 100644 --- a/build.rs +++ b/build.rs @@ -8,7 +8,8 @@ fn main() { // Cargo build --release -vv 可以看到println的内容。。 if cfg!(target_os = "windows") { Command::new("windres") - .args(&["config/favicon.rc", "-o"]) + .arg("config/favicon.rc") + .arg("-o") .arg(&format!("{}/favicon.o", out_dir)) .status() .unwrap(); diff --git a/src/server/methods/get.rs b/src/server/methods/get.rs index 02d0fe4..5bd0429 100644 --- a/src/server/methods/get.rs +++ b/src/server/methods/get.rs @@ -57,10 +57,7 @@ fn path_is_403(path: &Path) -> bool { } } fn file_to_resp(rc_s: Rc, req: &Request, path: &Path, mut map: HashMap) -> Response { - dbstln!("{}@{} file_to_resp(): {:?}", - module_path!(), - rc_s.time().ls(), - path); + dbstln!("file_to_resp(): {:?}", path); let ct = file_content_type(rc_s.clone(), path); let content = Content::File(File::open(path).unwrap()); map.insert("Content-Type".to_owned(), ct); @@ -96,10 +93,7 @@ fn file_content_type(rc_s: Rc, path: &Path) -> String { } fn sfs_to_resp(rc_s: Rc, req: &Request, path: &Path, mut map: HashMap) -> Response { - dbstln!("{}@{} sfs_to_resp(): {:?}", - module_path!(), - rc_s.time().ls(), - path); + dbstln!("sfs_to_resp(): {:?}", path); let exname = path.extension().unwrap().to_str().unwrap(); let doc = rc_s.arc().ents_doc(exname); let ct = if doc.as_str() != "text/plain; charset=utf-8" { @@ -123,10 +117,7 @@ fn sfs_to_resp(rc_s: Rc, req: &Request, path: &Path, mut map: HashMap< } pub fn other_status_code_to_resp(rc_s: Rc, req: &Request, mut map: HashMap) -> Response { - dbstln!("{}@{} other_status_code_to_resp(): {:?}", - module_path!(), - rc_s.time().ls(), - req.status); + dbstln!("other_status_code_to_resp(): {:?}", req.status); let code_name = (*rc_s.arc().cns().get(req.status()).unwrap()).to_owned(); let title = format!("{} {}", req.status(), code_name); let h1 = TagDouble::new("h1") @@ -153,10 +144,7 @@ pub fn other_status_code_to_resp(rc_s: Rc, req: &Request, mut map: Has } fn dir_to_resp(rc_s: Rc, req: &Request, path: &Path, mut map: HashMap) -> Response { - dbstln!("{}@{} dir_to_resp(): {:?}", - module_path!(), - rc_s.time().ls(), - path); + dbstln!("dir_to_resp(): {:?}", path); let content = Content::Str(dir_to_string(rc_s.clone(), req, path)); let ct = rc_s.arc().ents_doc("html"); map.insert("Content-Length".to_owned(), format!("{}", content.len())); @@ -236,20 +224,14 @@ fn dir_to_string(rc_s: Rc, req: &Request, path: &Path) -> Vec { let path_encoded = match quote(entry_name.clone(), b"") { Ok(ok) => ok, Err(_) => { - errstln!("{}@{}_Entry_encoding_error:\n{:?}", - module_path!(), - rc_s.time().ls(), - &path); + errstln!("Entry_encoding_error:\n{:?}", &path); entry_name.clone() } }; // 比如当前目录下有断开的链接时会陷入。 // if !Path::new(&entry_path).exists() { - // panic!("{}@{}_path_拼接_error:\n{:?}\n", - // module_path!(), - // rc_s.time().ls(), - // &entry_path); + // panic!("path_拼接_error:\n{:?}\n", &entry_path); // } // "/" 区分目录与文件(视觉),并且如果没有它,浏览器不会自动拼路径,这上面坑了好多时间。 diff --git a/src/server/methods/mod.rs b/src/server/methods/mod.rs index 4d14e92..00623fe 100644 --- a/src/server/methods/mod.rs +++ b/src/server/methods/mod.rs @@ -59,11 +59,9 @@ fn deal_client(config: Arc, mut stream: TcpStream) -> Result<(), io:: stream.set_write_timeout(Some(time_out))?; let rc_stream = Rc::from(RcStream::new(config, server_addr, client_addr)); - // println!("二分法 {:?}@{:?} {:?}@{:?}", + // println!("binary_search {:?}@{:?}", // rc_stream.time().as_str(), - // rc_stream.client_addr(), - // module_path!(), - // line!()); + // rc_stream.client_addr()); loop { let rc_s = rc_stream.clone(); let request_read = read_request(&mut stream)?; @@ -134,10 +132,7 @@ fn read_request(stream: &mut TcpStream) -> std::io::Result> { fn to_request(vec: &[u8], rc_s: Rc) -> Request { // "GET /favicon.ico HTTP/1.1\r\nHost: 127.0.0.1:8080\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nCookie: _ga=GA1.1.1204164507.1467299031\r\nConnection: keep-alive\r\n\r\n" let req_str = String::from_utf8_lossy(&vec[..]).into_owned(); - dbstln!("\n{}@{} req_raw:\n{:?}", - module_path!(), - rc_s.time().ls(), - req_str); + dbstln!("req_raw:\n{:?}", req_str); let mut req_str = req_str.lines(); let line = req_str.next().unwrap(); // 请求行 @@ -153,20 +148,11 @@ fn to_request(vec: &[u8], rc_s: Rc) -> Request { } } } - dbstln!("{}@{} header_HashMap:\n{:?}", - module_path!(), - rc_s.time().ls(), - header); + dbstln!("header_HashMap:\n{:?}", header); let url_raw = line[1].to_string(); - dbstln!("{}@{} url_raw: {:?}", - module_path!(), - rc_s.time().ls(), - &line[1]); + dbstln!("url_raw: {:?}", &line[1]); let url = url_handle_pre(&url_raw); - dbstln!("{}@{} url_handle_pre(): {:?}", - module_path!(), - rc_s.time().ls(), - &url); + dbstln!("url_handle_pre(): {:?}", &url); // 如果路径本身就存在,就不二次解码,(三次编码则会产生多余"/"等字符,不可能是真实路径。浏览器对URL只编码一次。 // Option<(String, String)> 完全匹配才赋值,is_none() 用于是否继续寻找。 let mut vp_rp_full_match: Option<(String, String)> = None; @@ -241,10 +227,8 @@ fn url_to_vp_rp(rc_s: Rc, url: &str, mut vp_rp_full_match: &mut Option if decoded_url[vp.len()..].starts_with('/') { break; } - dbstln!("{}@{}_url_sub_'/'_decoded: '{}' start_with(rp): \ + dbstln!("url_sub_'/'_decoded: '{}' start_with(rp): \ {:?}\nrp.join(decoded_url): {:?}", - module_path!(), - rc_s.time().ls(), &decoded_url, vp, Path::new(rp).join(Path::new(&decoded_url[vp.len()..]))); @@ -257,10 +241,7 @@ fn url_to_vp_rp(rc_s: Rc, url: &str, mut vp_rp_full_match: &mut Option } } } else { - dbstln!("{}_Warning@{}::url_to_vp_rp(): '{}' decode failed", - NAME, - module_path!(), - url); + dbstln!("{}_Warning@url_to_vp_rp(): '{}' decode failed", NAME, url); } } @@ -296,5 +277,9 @@ fn url_handle_pre(msg: &str) -> String { if !msg.ends_with('/') { raw.pop(); } + // win 上Path会自动加 "\\" ,然后尽数404 + if cfg!(windows) { + raw = raw[1..].to_string(); + } raw } diff --git a/src/server/methods/rc_stream.rs b/src/server/methods/rc_stream.rs index 4bf85e9..c779164 100755 --- a/src/server/methods/rc_stream.rs +++ b/src/server/methods/rc_stream.rs @@ -172,10 +172,7 @@ impl Response { Ok(()) } if let Err(e) = write_response(self, req, &mut stream) { - dbstln!("{}_Warning@{}::write_response(): {}", - NAME, - module_path!(), - e.description()); + dbstln!("{}_Warning@write_response(): {}", NAME, e.description()); }; } } @@ -194,9 +191,8 @@ impl Content { match file.metadata() { Ok(ok) => ok.len(), Err(e) => { - dbstln!("{}_Warning@{}::file_lenth(): {}@{:?}", + dbstln!("{}_Warning@file_lenth(): {}@{:?}", NAME, - module_path!(), e.description(), file); unreachable!(); @@ -211,10 +207,7 @@ impl Content { } pub fn write_content(self, mut stream: &mut TcpStream) { if let Err(e) = write_content_result(self, &mut stream) { - dbstln!("{}_Warning@{}::write_content(): {}", - NAME, - module_path!(), - e.description()); + dbstln!("{}_Warning@write_content(): {}", NAME, e.description()); }; } } diff --git a/util/bs/Cargo.toml b/util/bs/Cargo.toml index cf9f210..e29d516 100755 --- a/util/bs/Cargo.toml +++ b/util/bs/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "二分法叉虫子" +name = "binary_search" version = "0.1.0" authors = ["biluohc "] [dependencies] -stderr ="^0.7.0" +stderr ="0.7.1"