Refactor index code

This commit is contained in:
Vincent Ollivier 2024-04-02 22:28:44 +02:00
parent 6ab9ad713b
commit 2f349a19b2
1 changed files with 3 additions and 4 deletions

View File

@ -23,6 +23,7 @@ use smoltcp::wire::IpAddress;
const MAX_CONNECTIONS: usize = 32;
const POLL_DELAY_DIV: usize = 128;
const INDEX: [&str; 4] = ["", "/index.html", "/index.htm", "/index.txt"];
#[derive(Clone)]
struct Request {
@ -212,10 +213,8 @@ fn get(req: &Request, res: &mut Response) {
res.body.extend_from_slice(b"<h1>Moved Permanently</h1>\r\n");
} else {
let mut not_found = true;
for autocomplete in
&["", "/index.html", "/index.htm", "/index.txt"]
{
let real_path = format!("{}{}", res.real_path, autocomplete);
for index in INDEX {
let real_path = format!("{}{}", res.real_path, index);
if fs::is_dir(&real_path) {
continue;
}