From 3e1000e7c20e7e76089a0780b5dad0ecb6b6b158 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Tue, 12 May 2015 14:37:13 +0200 Subject: Trying to fix weird behaviour when used remotely (properly) --- src/sersve.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/sersve.rs b/src/sersve.rs index 023da9d..dc5f717 100644 --- a/src/sersve.rs +++ b/src/sersve.rs @@ -228,7 +228,7 @@ fn plain(content: &[u8]) -> IronResult { } fn html(content: &[u8]) -> IronResult { - plain(content).map(|r| r.set(Header(ContentType(Mime(TopLevel::Text, SubLevel::Html, Vec::new()))))) + plain(content).map(|r| r.set(Header(ContentType(Mime(TopLevel::Text, SubLevel::Html, vec![]))))) } fn from_path(path: &Path) -> IronResult { @@ -249,24 +249,24 @@ fn serve(req: &mut Request) -> IronResult { let mut path = root.clone(); for part in req.url.path.iter() { path.push(part) } - if !path.exists() { return html(b"Well, no... We don't have that today."); } + if !path.exists() { return html(format!("Error, `{}` does not exist.", path.display()).as_bytes()); } let filter = filter_str.and_then(|s| Regex::new(&s).ok()); if path.is_file() && path.starts_with(&root) { let stat = path.metadata(); - if stat.as_ref().ok().is_some() && max_size.is_some() && stat.ok().unwrap().len() > max_size.unwrap() { + if stat.as_ref().ok().is_some() + && max_size.is_some() + && stat.ok().unwrap().len() > max_size.unwrap() { return html(b"I'm afraid, I'm too lazy to serve the requested file. It's pretty big...") } - /*let content = match File::open(&path).read_to_end() { - Ok(s) => s, - Err(e) => return html(e.desc) - };*/ - if filter.as_ref().map_or(false, |f| !f.is_match(path.file_name().unwrap().to_string_lossy().borrow())) { + if filter.as_ref().map_or(false, + |f| !f.is_match(path.file_name().unwrap().to_string_lossy().borrow())) { return html(b"I don't think you're allowed to do this."); } - let mime: Option = path.extension().map(|s| s.to_string_lossy().to_owned()) + let mime: Option = path.extension() + .map(|s| s.to_string_lossy().to_owned()) .map_or(None, |e| mime_types.get_mime_type(e.borrow())) .and_then(|m| m.parse().ok()); if mime.as_ref().is_some() { @@ -293,9 +293,7 @@ fn main() { ARGS.flag_threads.unwrap_or(num_cpus::get())) }; - if ARGS.flag_fork { - fork(); - } + if ARGS.flag_fork { fork() } match Iron::new(serve).listen_with((host.as_ref(), port), threads, iron::Protocol::Http) { Ok(_) => (), -- cgit v1.2.3