🚧 Can index directories now, but a lot of stuff is missing

main
_ 2020-10-29 13:31:13 +00:00
parent af226cb36c
commit 8a301a6d03
2 changed files with 31 additions and 4 deletions

View File

@ -83,7 +83,7 @@ impl <'a> ResponseHandle <'a> {
async fn serve_dir (
response_handle: ResponseHandle <'_>,
dir: ReadDir
mut dir: ReadDir
) {
let (tx, rx) = channel (2);
@ -92,8 +92,35 @@ async fn serve_dir (
tx.send (Ok::<_, Infallible> (String::from ("<style>body {font-family:sans;}</style><ul>").into_bytes ())).await.unwrap ();
for i in 0u8..10 {
let s = format! ("<li><a href=\"{}\">Dir entry {}</a></li>\n", i, i);
while let Ok (entry) = dir.next_entry ().await {
let entry: tokio::fs::DirEntry = match entry {
Some (x) => x,
None => break,
};
let trailing_slash = match entry.file_type ().await {
Ok (t) => if t.is_dir () {
"/"
}
else {
""
},
Err (_) => "",
};
let file_name = match entry.file_name ().into_string () {
Ok (x) => x,
Err (_) => {
let s = format! ("<li>(file_name error)</li>\n");
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
{
break;
}
continue;
}
};
let s = format! ("<li><a href=\"{}{}\">{}{}</a></li>\n", file_name, trailing_slash, file_name, trailing_slash);
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
{
break;

View File

@ -1,5 +1,5 @@
- Index directories
- Handle trailing slash problem for directories
- Handle URL encoding for spaces in file names
- Set up tokens or something so clients can't trivially
impersonate servers
- Fix possible timing gap when refreshing http_listen (Just have client wait a few seconds?)