Use percent encoding for spaces in file names

main
_ 2020-10-30 16:46:03 -05:00
parent 5a690b287e
commit 2e2e6a5f32
3 changed files with 17 additions and 6 deletions

View File

@ -14,6 +14,7 @@ futures = "0.3"
http = "0.2"
hyper = "0.13"
lazy_static = "1.4"
percent-encoding = "2.1"
regex = "1"
reqwest = { version = "0.10.8", features = ["stream"] }
rmp-serde = "0.14.4"

View File

@ -120,7 +120,12 @@ async fn serve_dir (
}
};
let s = format! ("<li><a href=\"{}{}\">{}{}</a></li>\n", file_name, trailing_slash, file_name, trailing_slash);
use std::borrow::Cow;
use percent_encoding::*;
let percent_file_name: Cow <str> = utf8_percent_encode (&file_name, CONTROLS).into ();
let s = format! ("<li><a href=\"{}{}\">{}{}</a></li>\n", percent_file_name, trailing_slash, file_name, trailing_slash);
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
{
break;
@ -287,18 +292,23 @@ async fn handle_all (
//println! ("Step 6");
let mut path = PathBuf::from ("/home/user");
path.push (&uri [1..]);
use percent_encoding::*;
let encoded_path = &uri [1..];
let path = percent_decode (encoded_path.as_bytes ()).decode_utf8 ().unwrap ();
let mut full_path = PathBuf::from ("/home/user");
full_path.push (&*path);
let response_handle = ResponseHandle {
client,
req_id: &req_id,
};
if let Ok (dir) = read_dir (&path).await {
if let Ok (dir) = read_dir (&full_path).await {
serve_dir (response_handle, dir).await;
}
else if let Ok (file) = File::open (&path).await {
else if let Ok (file) = File::open (&full_path).await {
serve_file (
response_handle,
file,

View File

@ -1,6 +1,6 @@
- Handle URL encoding for spaces in file names
- Set up tokens or something so clients can't trivially
impersonate servers
- Offer list of clients at server root
- Fix possible timing gap when refreshing http_listen (Just have client wait a few seconds?)
- Parameter for server URL
- Parameter for static file serve path