Use percent encoding for spaces in file names
parent
5a690b287e
commit
2e2e6a5f32
|
@ -14,6 +14,7 @@ futures = "0.3"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
hyper = "0.13"
|
hyper = "0.13"
|
||||||
lazy_static = "1.4"
|
lazy_static = "1.4"
|
||||||
|
percent-encoding = "2.1"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
reqwest = { version = "0.10.8", features = ["stream"] }
|
reqwest = { version = "0.10.8", features = ["stream"] }
|
||||||
rmp-serde = "0.14.4"
|
rmp-serde = "0.14.4"
|
||||||
|
|
|
@ -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 ()
|
if tx.send (Ok::<_, Infallible> (s.into_bytes ())).await.is_err ()
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -287,18 +292,23 @@ async fn handle_all (
|
||||||
|
|
||||||
//println! ("Step 6");
|
//println! ("Step 6");
|
||||||
|
|
||||||
let mut path = PathBuf::from ("/home/user");
|
use percent_encoding::*;
|
||||||
path.push (&uri [1..]);
|
|
||||||
|
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 {
|
let response_handle = ResponseHandle {
|
||||||
client,
|
client,
|
||||||
req_id: &req_id,
|
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;
|
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 (
|
serve_file (
|
||||||
response_handle,
|
response_handle,
|
||||||
file,
|
file,
|
||||||
|
|
2
todo.md
2
todo.md
|
@ -1,6 +1,6 @@
|
||||||
- Handle URL encoding for spaces in file names
|
|
||||||
- Set up tokens or something so clients can't trivially
|
- Set up tokens or something so clients can't trivially
|
||||||
impersonate servers
|
impersonate servers
|
||||||
|
- Offer list of clients at server root
|
||||||
- Fix possible timing gap when refreshing http_listen (Just have client wait a few seconds?)
|
- Fix possible timing gap when refreshing http_listen (Just have client wait a few seconds?)
|
||||||
- Parameter for server URL
|
- Parameter for server URL
|
||||||
- Parameter for static file serve path
|
- Parameter for static file serve path
|
||||||
|
|
Loading…
Reference in New Issue