Skip to content

Commit

Permalink
remove: unneeded return statements
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai committed Oct 9, 2020
1 parent 56dec3e commit 295261d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
38 changes: 21 additions & 17 deletions src/handler/file_explorer/handler.rs
Expand Up @@ -21,11 +21,15 @@ pub fn file_explorer(request: Request, file_explorer: &FileExplorer) -> (Request
let mime_type = AsciiString::from_ascii(mime_type.as_bytes()).unwrap();
let file = File::open(entry.path).unwrap();

return (request, Response::from_file(file).with_header(tiny_http::Header {
field: "Content-Type".parse().unwrap(),
value: mime_type,
}).boxed()
);
(
request,
Response::from_file(file)
.with_header(tiny_http::Header {
field: "Content-Type".parse().unwrap(),
value: mime_type,
})
.boxed(),
)
} else {
let dirpath = entry.path.clone();
let dirpath = dirpath.to_str().unwrap();
Expand All @@ -41,20 +45,20 @@ pub fn file_explorer(request: Request, file_explorer: &FileExplorer) -> (Request
);
let mime_type_value: AsciiString = AsciiString::from_ascii("text/html").unwrap();
let response = Response::from_string(html)
.with_status_code(200)
.with_header(tiny_http::Header {
field: "Content-Type".parse().unwrap(),
value: mime_type_value,
});
.with_status_code(200)
.with_header(tiny_http::Header {
field: "Content-Type".parse().unwrap(),
value: mime_type_value,
});

return (request, response.boxed());
(request, response.boxed())
}
}
Err(_) => {
let response = Response::from_string("Not Found")
.with_status_code(404);

return (request, response.boxed());
}
Err(_) => (
request,
Response::from_string("Not Found")
.with_status_code(404)
.boxed(),
),
}
}
15 changes: 7 additions & 8 deletions src/handler/main_handler.rs
Expand Up @@ -5,13 +5,12 @@ use tiny_http::{Request, Response, ResponseBox};
/// The main handler acts like a router for every supported method.
/// If a method is not supported then responds with `Method Not Allowed 405`
pub fn main_handler(req: Request, fexplorer: &FileExplorer) -> (Request, ResponseBox) {
match req.method().to_string().to_lowercase().as_str() {
"get" => file_explorer(req, fexplorer),
_ => {
let response = Response::from_string("Method Not Allowed")
.with_status_code(405);
match req.method().to_string().to_lowercase().as_str() {
"get" => file_explorer(req, fexplorer),
_ => {
let response = Response::from_string("Method Not Allowed").with_status_code(405);

(req, response.boxed())
},
}
(req, response.boxed())
}
}
}

0 comments on commit 295261d

Please sign in to comment.